Merge branch 'master' into rel/3.0.0-preview
This commit is contained in:
Коммит
3ea5f4ea46
|
@ -24,6 +24,8 @@
|
|||
<UwpMetaPackageVersion>6.0.8</UwpMetaPackageVersion>
|
||||
<DefaultTargetPlatformVersion>17134</DefaultTargetPlatformVersion>
|
||||
<DefaultTargetPlatformMinVersion>14393</DefaultTargetPlatformMinVersion>
|
||||
|
||||
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\nupkg</PackageOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Choose>
|
||||
|
|
|
@ -452,7 +452,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
|||
_commandContainer = GetTemplateChild(PartCommandContainer) as Grid;
|
||||
if (_commandContainer != null)
|
||||
{
|
||||
_commandContainer.Background = LeftBackground as SolidColorBrush;
|
||||
_commandContainer.Background = LeftBackground as Brush;
|
||||
_commandContainer.Clip = new RectangleGeometry();
|
||||
_commandContainerTransform = new CompositeTransform();
|
||||
_commandContainer.Clip.Transform = _commandContainerTransform;
|
||||
|
@ -631,7 +631,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
|||
// If swiping from left to right, show left command panel.
|
||||
_rightCommandPanel.Opacity = 0;
|
||||
|
||||
_commandContainer.Background = LeftBackground as SolidColorBrush;
|
||||
_commandContainer.Background = LeftBackground as Brush;
|
||||
_commandContainer.Opacity = 1;
|
||||
_leftCommandPanel.Opacity = 1;
|
||||
|
||||
|
@ -672,7 +672,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
|||
// If swiping from right to left, show right command panel.
|
||||
_leftCommandPanel.Opacity = 0;
|
||||
|
||||
_commandContainer.Background = RightBackground as SolidColorBrush;
|
||||
_commandContainer.Background = RightBackground as Brush;
|
||||
_commandContainer.Opacity = 1;
|
||||
_rightCommandPanel.Opacity = 1;
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
<Style TargetType="controls:SlidableListItem">
|
||||
<Setter Property="LeftForeground" Value="White" />
|
||||
<Setter Property="RightForeground" Value="White" />
|
||||
<Setter Property="LeftBackground" Value="LightGray" />
|
||||
<Setter Property="RightBackground" Value="DarkGray" />
|
||||
<Setter Property="VerticalAlignment" Value="Stretch" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="ActivationWidth" Value="80" />
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
// Name of Content area in NavigationView Template.
|
||||
private const string CONTENT_GRID = "ContentGrid";
|
||||
|
||||
// Name of the 'Unselected' item we use to track null selection to workaround NavigationView behavior change in 17134.
|
||||
private const string UNSELECTED_ITEM_NAME = "UWPT_NVE_UNSELECTED";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the selected <see cref="NavigationViewItem"/>.
|
||||
/// </summary>
|
||||
|
@ -50,6 +53,32 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
/// </summary>
|
||||
public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.RegisterAttached("SelectedIndex", typeof(int), typeof(NavigationViewExtensions), new PropertyMetadata(-1, OnSelectedIndexChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value representing if the settings page is selected for the <see cref="NavigationViewItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="Windows.UI.Xaml.Controls.NavigationView"/>.</param>
|
||||
/// <returns>True if the settings page is selected.</returns>
|
||||
public static bool GetIsSettingsSelected(NavigationView obj)
|
||||
{
|
||||
return (bool)obj.GetValue(IsSettingsSelectedProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a value representing if the settings page is selected for the <see cref="NavigationViewItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="Windows.UI.Xaml.Controls.NavigationView"/>.</param>
|
||||
/// <param name="value">Set to True to select the settings page.</param>
|
||||
public static void SetIsSettingsSelected(NavigationView obj, bool value)
|
||||
{
|
||||
obj.SetValue(IsSettingsSelectedProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attached <see cref="DependencyProperty"/> for selecting the Settings Page of a <see cref="NavigationView"/>.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty IsSettingsSelectedProperty =
|
||||
DependencyProperty.RegisterAttached("IsSettingsSelected", typeof(bool), typeof(NavigationViewExtensions), new PropertyMetadata(false, OnIsSettingsSelectedChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Gets the behavior to collapse the content when clicking the already selected <see cref="NavigationViewItem"/>.
|
||||
/// </summary>
|
||||
|
@ -76,6 +105,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
public static readonly DependencyProperty CollapseOnClickProperty =
|
||||
DependencyProperty.RegisterAttached("CollapseOnClick", typeof(bool), typeof(NavigationViewExtensions), new PropertyMetadata(false, OnCollapseOnClickChanged));
|
||||
|
||||
// Private helper to mark a hidden object for 'unselected' state to work around not being able to set SelectedItem to null in 17134.
|
||||
private static NavigationViewItem GetSelectionPlaceholder(NavigationView obj)
|
||||
{
|
||||
return (NavigationViewItem)obj.GetValue(SelectionPlaceholderProperty);
|
||||
}
|
||||
|
||||
private static void SetSelectionPlaceholder(NavigationView obj, NavigationViewItem value)
|
||||
{
|
||||
obj.SetValue(SelectionPlaceholderProperty, value);
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for SelectionPlaceholder. This enables animation, styling, binding, etc...
|
||||
private static readonly DependencyProperty SelectionPlaceholderProperty =
|
||||
DependencyProperty.RegisterAttached("SelectionPlaceholder", typeof(NavigationViewItem), typeof(NavigationViewItem), new PropertyMetadata(null));
|
||||
|
||||
private static void OnCollapseOnClickChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
// This should always be a NavigationView.
|
||||
|
@ -102,19 +146,31 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
|
||||
private static void Navview_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
|
||||
{
|
||||
// We're doing this here instead of on property initialization
|
||||
// so that we add our 'dummy' item at the end of the list
|
||||
// and don't disrupt the order of the list.
|
||||
InjectSelectionPlaceholder(sender);
|
||||
|
||||
var content = sender.FindDescendantByName(CONTENT_GRID);
|
||||
|
||||
var unselected = GetSelectionPlaceholder(sender);
|
||||
if (content != null)
|
||||
{
|
||||
// If we click the item we already have selected, we want to collapse our content
|
||||
if (sender.SelectedItem != null && args.InvokedItem.Equals(((NavigationViewItem)sender.SelectedItem).Content))
|
||||
/* Bug with NavView fires twice for Settings, so we can't use this logic until fixed...
|
||||
* (GetIsSettingsSelected(sender) ?
|
||||
args.InvokedItem == sender.SelectedItem :
|
||||
args.InvokedItem.Equals(((NavigationViewItem)sender.SelectedItem).Content))
|
||||
*/
|
||||
if (sender.SelectedItem != null && sender.SelectedItem != unselected &&
|
||||
args.InvokedItem.Equals(((NavigationViewItem)sender.SelectedItem).Content))
|
||||
{
|
||||
// We need to dispatch this so the underlying selection event from our invoke processes.
|
||||
// Otherwise, we just end up back where we started. We don't care about waiting for this to finish.
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
sender.Dispatcher.RunIdleAsync((e) =>
|
||||
{
|
||||
sender.SelectedItem = null;
|
||||
sender.SelectedItem = unselected;
|
||||
});
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
|
||||
|
@ -127,10 +183,33 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
}
|
||||
}
|
||||
|
||||
// Check if we've injected our workaround or not yet for 17134 (prevents setting SelectedItem back to null).
|
||||
private static void InjectSelectionPlaceholder(NavigationView sender)
|
||||
{
|
||||
if (sender != null && GetSelectionPlaceholder(sender) == null)
|
||||
{
|
||||
var temp = new NavigationViewItem()
|
||||
{
|
||||
Content = UNSELECTED_ITEM_NAME,
|
||||
Visibility = Visibility.Collapsed
|
||||
};
|
||||
|
||||
sender.MenuItems.Add(temp);
|
||||
SetSelectionPlaceholder(sender, temp);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var navview = (NavigationView)d;
|
||||
|
||||
// If we're trying to unselect something, inject then.
|
||||
// Otherwise we'll mess up starting order of items and indices.
|
||||
if (e.NewValue as int? == -1)
|
||||
{
|
||||
InjectSelectionPlaceholder(navview);
|
||||
}
|
||||
|
||||
navview.Loaded -= Navview_Loaded;
|
||||
Navview_Loaded(d, null); // For changes
|
||||
navview.Loaded += Navview_Loaded;
|
||||
|
@ -139,6 +218,20 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
navview.SelectionChanged += Obj_SelectionChanged;
|
||||
}
|
||||
|
||||
private static void OnIsSettingsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var navview = (NavigationView)d;
|
||||
|
||||
if (e.NewValue.Equals(true))
|
||||
{
|
||||
navview.SelectedItem = navview.SettingsItem;
|
||||
}
|
||||
else if (navview.SelectedItem == navview.SettingsItem)
|
||||
{
|
||||
navview.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Navview_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var navview = (NavigationView)sender;
|
||||
|
@ -147,21 +240,41 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
|
||||
if (value >= 0 && value < navview.MenuItems.Count)
|
||||
{
|
||||
// Skip over our hidden item, if needed.
|
||||
if (navview.MenuItems[value] == GetSelectionPlaceholder(navview))
|
||||
{
|
||||
value++;
|
||||
if (value >= navview.MenuItems.Count)
|
||||
{
|
||||
navview.SelectedItem = GetSelectionPlaceholder(navview);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if we need to.
|
||||
if (navview.SelectedItem == null || !navview.SelectedItem.Equals(navview.MenuItems[value] as NavigationViewItem))
|
||||
{
|
||||
navview.SelectedItem = navview.MenuItems[value];
|
||||
}
|
||||
}
|
||||
else if (GetIsSettingsSelected(navview))
|
||||
{
|
||||
navview.SelectedItem = navview.SettingsItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
navview.SelectedItem = null;
|
||||
navview.SelectedItem = GetSelectionPlaceholder(navview);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Obj_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||
{
|
||||
if (!args.IsSettingsSelected && args.SelectedItem != null)
|
||||
// Store state of settings selected.
|
||||
SetIsSettingsSelected(sender, args.IsSettingsSelected);
|
||||
|
||||
if (!args.IsSettingsSelected && args.SelectedItem != null &&
|
||||
args.SelectedItem != GetSelectionPlaceholder(sender))
|
||||
{
|
||||
var index = sender.MenuItems.IndexOf(args.SelectedItem);
|
||||
if (index != GetSelectedIndex(sender))
|
||||
|
@ -175,4 +288,4 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,9 @@
|
|||
title:
|
||||
author: GitHub_UserName
|
||||
description: describe your control in one sentence
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, your control name
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, your control name
|
||||
dev_langs:
|
||||
- csharp
|
||||
---
|
||||
|
||||
<!-- To know about all the available Markdown syntax, Check out https://docs.microsoft.com/contribute/contribute/how-to-write-use-markdown -->
|
||||
|
@ -12,7 +14,7 @@ keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, your control name
|
|||
# Title
|
||||
<!-- Describe your control -->
|
||||
The [Control Name](API-Link) ...
|
||||
<!-- You can get your API link from https://docs.microsoft.com/dotnet/api/?term=Microsoft.Toolkit. Make sure you remove the "?view=uwp-toolkit-x.x.x" from the end and country specfic keyword like "en-us" of the URL eg: https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.helpers.printhelper -->
|
||||
<!-- You can get your API link from https://docs.microsoft.com/dotnet/api/?term=Microsoft.Toolkit. Make sure you remove the "?view=uwp-toolkit-x.x.x" from the end and country specific keyword like "en-us" of the URL eg: https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.helpers.printhelper -->
|
||||
|
||||
<!-- Use below format to display note
|
||||
> [!NOTE]
|
||||
|
@ -30,6 +32,11 @@ Some warning note
|
|||
```csharp
|
||||
|
||||
```
|
||||
<!-- VB.Net samples are optional. If included, 'vb' should also be listed in the 'dev_langs' defined in the header
|
||||
```vb
|
||||
|
||||
```
|
||||
-->
|
||||
|
||||
```xaml
|
||||
|
||||
|
@ -85,7 +92,7 @@ Some warning note
|
|||
|
||||
## Requirements
|
||||
|
||||
| Device family | Universal, MinVertion or higher |
|
||||
| Device family | Universal, MinVersion or higher |
|
||||
| -- | -- |
|
||||
| Namespace | |
|
||||
| NuGet package | [NuGet package](NuGet-package-link) |
|
||||
|
|
|
@ -3,6 +3,9 @@ title: AnimationSet class
|
|||
author: Vijay-Nirmal
|
||||
description: The AnimationSet class defines an object for storing and managing Storyboard and CompositionAnimations for an element
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, animationset, animationset class
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# AnimationSet
|
||||
|
@ -15,7 +18,7 @@ The AnimationSet class defines an object for storing and managing Storyboard and
|
|||
<Page ...
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"/>
|
||||
|
||||
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactivity:BehaviorCollection>
|
||||
<behaviors:Blur Value="10" Duration="2500" AutomaticallyStart="True"/>
|
||||
|
@ -31,6 +34,12 @@ anim.SetDurationForAll(2500);
|
|||
anim.SetDelay(250);
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Light(5).Offset(offsetX:=100, offsetY:=100).Saturation(0.5).Scale(scaleX:=2, scaleY:=2)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -107,7 +116,7 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
preElement.Blur(value: 0).Fade(value: 1).Scale(centerX: 100, centerY: 100, easingType: EasingType.Sine)
|
||||
.SetDurationForAll(500)
|
||||
.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void MyUIElement_PointerExited(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
|
@ -119,6 +128,19 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub MyUIElement_PointerEntered(ByVal sender As Object, ByVal e As PointerRoutedEventArgs)
|
||||
preElement = TryCast(sender, FrameworkElement)
|
||||
preElement.Blur(value:=0).Fade(value:=1).Scale(centerX:=100, centerY:=100, easingType:=EasingType.Sine).SetDurationForAll(500).Start()
|
||||
End Sub
|
||||
|
||||
Private Sub MyUIElement_PointerExited(ByVal sender As Object, ByVal e As PointerRoutedEventArgs)
|
||||
If preElement IsNot Nothing Then
|
||||
preElement.Blur(value:=0).Fade(value:=0.1F).Scale(scaleX:=0.5F, scaleY:=0.5F, centerX:=100, centerY:=100, easingType:=EasingType.Sine).SetDurationForAll(500).Start()
|
||||
End If
|
||||
End Sub
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
![Use Case 1 Output](../resources/images/Animations/AnimationSet/Use-Case-1.gif)
|
||||
|
@ -128,10 +150,19 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
|
||||
```csharp
|
||||
MyUIElement.Blur(value: 10).Fade(value: 0.5f)
|
||||
.Then()
|
||||
.Fade(value: 1).Scale(scaleX: 2, scaleY: 2, centerX: 100, centerY: 100, easingType: EasingType.Sine)
|
||||
.SetDurationForAll(2500)
|
||||
.Start();
|
||||
.Then()
|
||||
.Fade(value: 1).Scale(scaleX: 2, scaleY: 2, centerX: 100, centerY: 100, easingType: EasingType.Sine)
|
||||
.SetDurationForAll(2500)
|
||||
.Start();
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Blur(value:=10) _
|
||||
.Fade(value:=0.5F) _
|
||||
.[Then]() _
|
||||
.Fade(value:=1) _
|
||||
.Scale(scaleX:=2, scaleY:=2, centerX:=100, centerY:=100, easingType:=EasingType.Sine) _
|
||||
.SetDurationForAll(2500) _
|
||||
.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Blur animation behavior
|
|||
author: nmetulev
|
||||
description: The UWP Community Toolkit Blur animation behavior selectively blurs a XAML element by increasing or decreasing pixel size
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, blur, blur animation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Blur
|
||||
|
@ -28,7 +31,11 @@ The [Blur animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp
|
|||
|
||||
```csharp
|
||||
MyUIElement.Blur(value: 5, duration: 2500, delay: 250).Start();
|
||||
await MyUIElement.Blur(value: 5, duration: 2500, delay: 250).StartAsync(); //Blur animation can be awaited
|
||||
await MyUIElement.Blur(value: 5, duration: 2500, delay: 250).StartAsync(); // Blur animation can be awaited
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Blur(value:=5, duration:=2500, delay:=250).Start()
|
||||
Await MyUIElement.Blur(value:=5, duration:=2500, delay:=250).StartAsync() ' Blur animation can be awaited
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
@ -84,7 +91,14 @@ await MyUIElement.Blur(value: 5, duration: 2500, delay: 250).StartAsync(); //Bl
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
|
||||
```vb
|
||||
Dim anim = MyUIElement.Blur(5).Fade(0.5F).Rotate(30)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
![Use Case 2 Output](../resources/images/Animations/Chaining-Animations-Blur-Fade-Rotate.gif)
|
||||
|
|
|
@ -96,7 +96,7 @@ A brief recap of ExpressionAnimations:
|
|||
|
||||
- For more information on ExpressionAnimations, [please check our documentation](https://docs.microsoft.com/uwp/api/Windows.UI.Composition.ExpressionAnimation).
|
||||
|
||||
ExpressionAnimations can create some very powerful and unique experiences, but can be a bit combersome to author. One of the big pain points with ExpressionAnimations is that the equation or mathematical relationship that defines the animation is written as a string, e.g.:
|
||||
ExpressionAnimations can create some very powerful and unique experiences, but can be a bit cumbersome to author. One of the big pain points with ExpressionAnimations is that the equation or mathematical relationship that defines the animation is written as a string, e.g.:
|
||||
|
||||
```csharp
|
||||
_parallaxExpression = compositor.CreateExpressionAnimation(
|
||||
|
@ -450,7 +450,7 @@ _visual.StartAnimation("Offset", newPosition);
|
|||
|
||||
- Create a named parameter using the static methods off ExpressionValues.Constants class
|
||||
|
||||
You can create a constant parameter via static Create\*Parameter() methods (e.g. ExpressionValues.Constants.CreateScalarParameter(“foo”, 7)). Note: setting the intial value as part of the creation is optional; you can always set the value of the parameter using ExpressionNode.Set\*Parameter(). Let’s expand the above example. In this case, let’s say we want to create a generic equation that can be reused for similar scenarios, but tailored by changing the value of constant(s). In the example below, we create the Expression that contains a Constant Parameter, using ExpressionValues.Constant.CreateConstantVector3(…). Before connecting it to a target, the Expression is tailored by setting the parameter using ExpressionNode.SetVector3Parameter(…).
|
||||
You can create a constant parameter via static Create\*Parameter() methods (e.g. ExpressionValues.Constants.CreateScalarParameter(“foo”, 7)). Note: setting the initial value as part of the creation is optional; you can always set the value of the parameter using ExpressionNode.Set\*Parameter(). Let’s expand the above example. In this case, let’s say we want to create a generic equation that can be reused for similar scenarios, but tailored by changing the value of constant(s). In the example below, we create the Expression that contains a Constant Parameter, using ExpressionValues.Constant.CreateConstantVector3(…). Before connecting it to a target, the Expression is tailored by setting the parameter using ExpressionNode.SetVector3Parameter(…).
|
||||
|
||||
```csharp
|
||||
var delta = new Vector3(50.0f);
|
||||
|
@ -584,7 +584,7 @@ deltaExpression.SetReferenceParameter("visual", _blueBall);
|
|||
_visualB.StartAnimation("Offset", deltaExpression);
|
||||
```
|
||||
|
||||
A real-world example that demonstrates the need for changing the value of a Parameter using diffferent constants would be using the index number of an itemized List as a Constant Parameter.
|
||||
A real-world example that demonstrates the need for changing the value of a Parameter using different constants would be using the index number of an itemized List as a Constant Parameter.
|
||||
|
||||
We can extend this concept by imagining a real-world scenario in which a common equation is needed across many targets: list items. A list is typically comprised of homogeneous items, each with a unique ID indicating its position in the list. Each item needs to be behave very similarly, with slight differences based on its position. For this example, a single Expression could be designed that gives a consistent behavior across all items, but is customized by using the list item ID as a Constant Parameter. When connecting this Expression template to each list item, the ID Parameter is set using SetScalarParameter(…) with the ID of the current list item.
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Fade animation behavior
|
|||
author: nmetulev
|
||||
description: The Fade animation behavior fades objects, in and out, over time and delay. It can be used along side other animations directly through XAML or code
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, fade, fade animation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Fade
|
||||
|
@ -30,6 +33,10 @@ The [Fade animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp
|
|||
MyUIElement.Fade(value: 0.5f, duration: 2500, delay: 250, easingType: EasingType.Default).Start();
|
||||
await MyUIElement.Fade(value: 0.5f, duration: 2500, delay: 250, easingType: EasingType.Default).StartAsync(); //Fade animation can be awaited
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Fade(value:=0.5F, duration:=2500, delay:=250, easingType:=EasingType.[Default]).Start()
|
||||
Await MyUIElement.Fade(value:=0.5F, duration:=2500, delay:=250, easingType:=EasingType.[Default]).StartAsync() ' Fade animation can be awaited
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -82,6 +89,13 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Fade(0.5F).Blur(5).Rotate(30)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: FadeHeader Behavior
|
|||
author: nmetulev
|
||||
description: The FadeHeader Behavior fades a ListView or GridView Header UIElement when the user scrolls.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, fadeheader, fadeheader behavior
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# FadeHeader
|
||||
|
@ -52,12 +55,18 @@ The [FadeHeader](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.ui.
|
|||
```csharp
|
||||
Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(new FadeHeaderBehavior());
|
||||
```
|
||||
```vb
|
||||
Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(New FadeHeaderBehavior())
|
||||
```
|
||||
|
||||
***Explicit usage***:
|
||||
|
||||
```csharp
|
||||
Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(new FadeHeaderBehavior { HeaderElement = MyHeaderGrid });
|
||||
```
|
||||
```vb
|
||||
Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(New FadeHeaderBehavior With {.HeaderElement = MyHeaderGrid})
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Light animation behavior
|
|||
author: nmetulev
|
||||
description: The Light animation behavior performs a point light in the middle of a given UIElement.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, light, light animation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Light
|
||||
|
@ -34,6 +37,10 @@ Heavy usage of effects may have a negative impact on the performance of your app
|
|||
MyUIElement.Light(distance: 5, duration: 2500, delay: 250, color: Colors.Red).Start();
|
||||
await MyUIElement.Light(distance: 5, duration: 2500, delay: 250, color: Colors.Red).StartAsync(); //Light animation can be awaited
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Light(distance:=5, duration:=2500, delay:=250, color:=Colors.Red).Start()
|
||||
Await MyUIElement.Light(distance:=5, duration:=2500, delay:=250, color:=Colors.Red).StartAsync() ' Light animation can be awaited
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -69,6 +76,13 @@ await MyUIElement.Light(distance: 5, duration: 2500, delay: 250, color: Colors.R
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Light(5).Offset(offsetX:=100, offsetY:=100).Saturation(0.5).Scale(scaleX:=2, scaleY:=2)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Offset animation behavior
|
|||
author: nmetulev
|
||||
description: The Offset animation behavior gets the number of pixels, from the origin of the associated control, then offsets the control.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, offset animation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Offset
|
||||
|
@ -31,6 +34,10 @@ The [Offset animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.u
|
|||
MyUIElement.Offset(offsetX: 25, offsetY: 25, duration: 2500, delay: 250, easingType: EasingType.Default).Start();
|
||||
await MyUIElement.Offset(offsetX: 25, offsetY: 25, duration: 2500, delay: 250, easingType: EasingType.Default).StartAsync(); //Offset animation can be awaited
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Offset(offsetX:=25, offsetY:=25, duration:=2500, delay:=250, easingType:=EasingType.[Default]).Start()
|
||||
Await MyUIElement.Offset(offsetX:=25, offsetY:=25, duration:=2500, delay:=250, easingType:=EasingType.[Default]).StartAsync() ' Offset animation can be awaited
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -73,14 +80,17 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
|
||||
## Examples
|
||||
|
||||
- You can just call `Offset()` set the control in the orginal position
|
||||
- You can just call `Offset()` set the control in the original position
|
||||
|
||||
**Sample Code**
|
||||
|
||||
```csharp
|
||||
await MyUIElement.Offset().Start();
|
||||
```
|
||||
- Use await to create a continous movement
|
||||
```vb
|
||||
Await MyUIElement.Offset().Start()
|
||||
```
|
||||
- Use await to create a continuous movement
|
||||
|
||||
**Sample Code**
|
||||
|
||||
|
@ -93,6 +103,14 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
await MyUIElement.Offset(duration: 1000).StartAsync();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Public Async Function OffsetAsync() As Task
|
||||
Await MyUIElement.Offset(offsetX:=100, duration:=1000).StartAsync()
|
||||
Await MyUIElement.Offset(offsetX:=100, offsetY:=100, duration:=1000).StartAsync()
|
||||
Await MyUIElement.Offset(offsetX:=0, offsetY:=100, duration:=1000).StartAsync()
|
||||
Await MyUIElement.Offset(duration:=1000).StartAsync()
|
||||
End Function
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
@ -109,6 +127,13 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Light(5).Offset(offsetX:=100, offsetY:=100).Saturation(0.5).Scale(scaleX:=2, scaleY:=2)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: ParallaxService
|
|||
author: nmetulev
|
||||
description: The ParallaxService class allows to create a parallax effect for items contained within an element that scrolls like a ScrollViewer or ListView.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, parallaxservice
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# ParallaxService
|
||||
|
@ -29,6 +32,10 @@ The [ParallaxService class](https://docs.microsoft.com/dotnet/api/microsoft.tool
|
|||
ParallaxService.SetHorizontalMultiplier(MyUIElement, 0.5)
|
||||
ParallaxService.SetVerticalMultiplier(MyUIElement, 0.5)
|
||||
```
|
||||
```vb
|
||||
MyUIElement.SetValue(ParallaxService.VerticalMultiplierProperty, 0.5)
|
||||
MyUIElement.SetValue(ParallaxService.HorizontalMultiplierProperty, 0.5)
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: ReorderGridAnimation
|
|||
author: nmetulev
|
||||
description: The ReorderGridAnimation class allows your GridView controls to animate items into position when the size of the GridView changes.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, ReorderGridAnimation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# ReorderGridAnimation
|
||||
|
@ -21,6 +24,9 @@ The [ReorderGridAnimation class](https://docs.microsoft.com/dotnet/api/microsoft
|
|||
```csharp
|
||||
MyGridView.SetValue(ReorderGridAnimation.DurationProperty, 250);
|
||||
```
|
||||
```vb
|
||||
MyGridView.SetValue(ReorderGridAnimation.DurationProperty, 250)
|
||||
```
|
||||
## Sample Output
|
||||
|
||||
![ReorderGridAnimation](../resources/images/Animations/ReorderGridAnimation/Sample-Output.gif)
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Rotate animation behavior
|
|||
author: nmetulev
|
||||
description: The Rotate animation behavior allows users to modify and animate the control's rotation.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, rotate, rotate animation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Rotate
|
||||
|
@ -30,8 +33,12 @@ The [Rotate animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.u
|
|||
```
|
||||
|
||||
```csharp
|
||||
MyUIElement.Rotate(value: 0.5f, centerX: 0.0f, centerY: 0.0f, duration: 2500, delay: 250, easingType: EasingType.Default).Start();
|
||||
await MyUIElement.Rotate(value: 0.5f, centerX: 0.0f, centerY: 0.0f, duration: 2500, delay: 250, easingType: EasingType.Default).StartAsync(); //Rotate animation can be awaited
|
||||
MyUIElement.Rotate(value: 50.0f, centerX: 0.0f, centerY: 0.0f, duration: 2500, delay: 250, easingType: EasingType.Default).Start();
|
||||
await MyUIElement.Rotate(value: 50.0f, centerX: 0.0f, centerY: 0.0f, duration: 2500, delay: 250, easingType: EasingType.Default).StartAsync(); //Rotate animation can be awaited
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Rotate(value:=50.0F, centerX:=0F, centerY:=0F, duration:=2500, delay:=250, easingType:=EasingType.[Default]).Start()
|
||||
Await MyUIElement.Rotate(value:=50.0F, centerX:=0F, centerY:=0F, duration:=2500, delay:=250, easingType:=EasingType.[Default]).StartAsync() ' Rotate animation can be awaited
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
@ -87,6 +94,13 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Rotate(30).Fade(0.5F).Blur(5)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Saturation animation behavior
|
|||
author: nmetulev
|
||||
description: The Saturation animation behavior selectively saturates a XAML element.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, saturation animation, saturation
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Saturation
|
||||
|
@ -30,6 +33,9 @@ The [Saturation animation](https://docs.microsoft.com/dotnet/api/microsoft.toolk
|
|||
MyUIElement.Saturation(value: 0.5, duration: 500, delay: 250).Start();
|
||||
await MyUIElement.Saturation(value: 0.5, duration: 500, delay: 250).StartAsync(); //Saturation animation can be awaited
|
||||
```
|
||||
```vb
|
||||
ToolkitLogo.Saturation(value:=0, duration:=500, delay:=250)
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -67,6 +73,15 @@ await MyUIElement.Saturation(value: 0.5, duration: 500, delay: 250).StartAsync()
|
|||
MyUIElement.Saturation(value: 0).Start();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub MyUIElement_PointerEntered(sender As Object, e As PointerRoutedEventArgs)
|
||||
MyUIElement.Saturation(value:=1).Start()
|
||||
End Sub
|
||||
|
||||
Private Sub MyUIElement_PointerExited(sender As Object, e As PointerRoutedEventArgs)
|
||||
MyUIElement.Saturation(value:=0).Start()
|
||||
End Sub
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
@ -83,6 +98,13 @@ await MyUIElement.Saturation(value: 0.5, duration: 500, delay: 250).StartAsync()
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Light(5).Offset(offsetX:=100, offsetY:=100).Saturation(0.5).Scale(scaleX:=2, scaleY:=2)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Scale animation behavior
|
|||
author: nmetulev
|
||||
description: The Scale animation behavior allows you to change a control's scale by increasing or decreasing the control through animation.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, scale animation, scale
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Scale
|
||||
|
@ -13,7 +16,7 @@ The [Scale animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uw
|
|||
|
||||
```xaml
|
||||
<Page ...
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"/>
|
||||
|
||||
<interactivity:Interaction.Behaviors>
|
||||
|
@ -28,6 +31,9 @@ The [Scale animation](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uw
|
|||
```csharp
|
||||
MyUIElement.Scale(scaleX: 2, scaleY: 2, centerX: 0, centerY: 0, duration: 2500, delay: 250, easingType: EasingType.Default).Start();
|
||||
```
|
||||
```vb
|
||||
MyUIElement.Scale(scaleX:=2, scaleY:=2, centerX:=0, centerY:=0, duration:=2500, delay:=250, easingType:=EasingType.[Default]).Start()
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
||||
|
@ -90,6 +96,20 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
lastTapped.Scale(scaleX: 2, scaleY: 2, centerX: 50, centerY: 50).Start();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private lastTapped As UIElement = Nothing
|
||||
|
||||
Private Sub MyUIElement_Tapped(ByVal sender As Object, ByVal e As TappedRoutedEventArgs)
|
||||
If lastTapped IsNot Nothing Then
|
||||
lastTapped.Scale(centerX:=50, centerY:=50).Start()
|
||||
Canvas.SetZIndex(lastTapped, 0)
|
||||
End If
|
||||
|
||||
lastTapped = TryCast(sender, UIElement)
|
||||
Canvas.SetZIndex(lastTapped, 1)
|
||||
lastTapped.Scale(scaleX:=2, scaleY:=2, centerX:=50, centerY:=50).Start()
|
||||
End Sub
|
||||
```
|
||||
**Sample Output**
|
||||
|
||||
![Use Case 1 Output](../resources/images/Animations/Scale/Sample-Output.gif)
|
||||
|
@ -105,6 +125,13 @@ You can change the way how the animation interpolates between keyframes by defin
|
|||
anim.Completed += animation_completed;
|
||||
anim.Start();
|
||||
```
|
||||
```vb
|
||||
Dim anim = MyUIElement.Light(5).Offset(offsetX:=100, offsetY:=100).Saturation(0.5).Scale(scaleX:=2, scaleY:=2)
|
||||
anim.SetDurationForAll(2500)
|
||||
anim.SetDelay(250)
|
||||
AddHandler anim.Completed, AddressOf animation_completed
|
||||
anim.Start()
|
||||
```
|
||||
|
||||
**Sample Output**
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: AdaptiveGridView XAML Control
|
|||
author: nmetulev
|
||||
description: The AdaptiveGridView Control presents items in a evenly-spaced set of columns to fill the total available display space.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, AdaptiveGridView, xaml control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# AdaptiveGridView XAML Control
|
||||
|
@ -100,6 +103,15 @@ ItemHeight property must be set when OneRowModeEnabled property set as `true`
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Public Class AspectContentControl
|
||||
Inherits ContentControl
|
||||
|
||||
Protected Overrides Function MeasureOverride(ByVal availableSize As Size) As Size
|
||||
Return New Size(availableSize.Width, availableSize.Width * 1.6)
|
||||
End Function
|
||||
End Class
|
||||
```
|
||||
|
||||
_ItemTemplate implementation_
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: BladeView XAML Control
|
|||
author: nmetulev
|
||||
description: The BladeView provides a container to host blades as extra detail pages in, for example, a master-detail scenario.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, BladeView, XAML Control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# BladeView XAML Control
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
---
|
||||
title: Carousel XAML Control
|
||||
author: nmetulev
|
||||
description: The Carousel control inherites from ItemsControl, representing a nice and smooth carousel.
|
||||
description: The Carousel control inherits from ItemsControl, representing a nice and smooth carousel.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, carousel, xaml control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Carousel XAML Control
|
||||
|
|
|
@ -17,8 +17,8 @@ The [DropShadowPanel Control](https://docs.microsoft.com/dotnet/api/microsoft.to
|
|||
|
||||
<controls:DropShadowPanel BlurRadius="4.0" ShadowOpacity="0.70"
|
||||
OffsetX="5.0" OffsetY="5.0" Color="Black">
|
||||
<Image Width="200" Source="Unicorn.png" Stretch="Uniform"/>
|
||||
</controls:DropShadowPanel>
|
||||
<Image Width="200" Source="Unicorn.png" Stretch="Uniform"/>
|
||||
</controls:DropShadowPanel>
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
|
@ -49,7 +49,12 @@ The [DropShadowPanel Control](https://docs.microsoft.com/dotnet/api/microsoft.to
|
|||
if(!DropShadowPanel.IsSupported)
|
||||
{
|
||||
// Change something to counter the lack of drop shadow
|
||||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
If Not DropShadowPanel.IsSupported Then
|
||||
' Change something to counter the lack of drop shadow
|
||||
End If
|
||||
```
|
||||
|
||||
## Default Template
|
||||
|
|
|
@ -3,6 +3,9 @@ title: HamburgerMenu XAML Control
|
|||
author: nmetulev
|
||||
description: The Hamburger Menu Control provides an easy-to-use, side-bar menu which users can show or hide by using a Hamburger button
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, HamburgerMenu, xaml control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# HamburgerMenu XAML Control
|
||||
|
@ -151,6 +154,47 @@ namespace HamburgerSample
|
|||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Public NotInheritable Class MainPage
|
||||
Inherits Page
|
||||
|
||||
Sub New()
|
||||
InitializeComponent()
|
||||
|
||||
hamburgerMenuControl.ItemsSource = MenuItem.GetMainItems()
|
||||
hamburgerMenuControl.OptionsItemsSource = MenuItem.GetOptionsItems()
|
||||
End Sub
|
||||
|
||||
Private Sub OnMenuItemClick(sender As Object, e As ItemClickEventArgs)
|
||||
Dim menuItem = TryCast(e.ClickedItem, MenuItem)
|
||||
contentFrame.Navigate(menuItem.PageType)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class MenuItem
|
||||
|
||||
Public Property Icon As Symbol
|
||||
|
||||
Public Property Name As String
|
||||
|
||||
Public Property PageType As Type
|
||||
|
||||
Public Shared Function GetMainItems() As List(Of MenuItem)
|
||||
Dim items = New List(Of MenuItem)()
|
||||
items.Add(New MenuItem() With {.Icon = Symbol.Accept, .Name = "MenuItem1", .PageType = GetType(Views.BlankPage1)})
|
||||
items.Add(New MenuItem() With {.Icon = Symbol.Send, .Name = "MenuItem2", .PageType = GetType(Views.BlankPage1)})
|
||||
items.Add(New MenuItem() With {.Icon = Symbol.Shop, .Name = "MenuItem3", .PageType = GetType(Views.BlankPage1)})
|
||||
Return items
|
||||
End Function
|
||||
|
||||
Public Shared Function GetOptionsItems() As List(Of MenuItem)
|
||||
Dim items = New List(Of MenuItem)()
|
||||
items.Add(New MenuItem() With {.Icon = Symbol.Setting, .Name = "OptionItem1", .PageType = GetType(Views.BlankPage1)})
|
||||
Return items
|
||||
End Function
|
||||
End Class
|
||||
|
||||
```
|
||||
|
||||
## <a name="navview"></a> Moving to NavigationView
|
||||
|
@ -177,6 +221,11 @@ The HamburgerMenu and NavigationView share the same concepts and provide the sam
|
|||
settingsItem.Content = "About";
|
||||
settingsItem.Icon = new FontIcon() { Glyph = "?" };
|
||||
```
|
||||
```vb
|
||||
Dim settingsItem = TryCast(HamburgerMenu.SettingsItem, NavigationViewItem)
|
||||
settingsItem.Content = "About"
|
||||
settingsItem.Icon = New FontIcon() With {.Glyph = "?"}
|
||||
```
|
||||
|
||||
- Free-form content in the pane’s footer, by adding any content in the new *PaneFooter* property
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: InAppNotification XAML Control
|
|||
author: nmetulev
|
||||
description: The InAppNotification control offers the ability to show local notifications in your application.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, InAppNotification, in app notification, xaml control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# InAppNotification
|
||||
|
@ -75,12 +78,18 @@ You can change this behavior with one of these values:
|
|||
```csharp
|
||||
ExampleInAppNotification.Show();
|
||||
```
|
||||
```vb
|
||||
ExampleInAppNotification.Show()
|
||||
```
|
||||
|
||||
- By using a simple text content.
|
||||
|
||||
```csharp
|
||||
ExampleInAppNotification.Show("Some text.");
|
||||
```
|
||||
```vb
|
||||
ExampleInAppNotification.Show("Some text.")
|
||||
```
|
||||
|
||||
- By using a UIElement (with a container as parent, ex: Grid)
|
||||
|
||||
|
@ -90,6 +99,12 @@ You can change this behavior with one of these values:
|
|||
// TODO : Construct the Grid in C#
|
||||
ExampleInAppNotification.Show(grid);
|
||||
```
|
||||
```vb
|
||||
Dim grid = New Grid()
|
||||
|
||||
' TODO : Construct the Grid in code
|
||||
ExampleInAppNotification.Show(grid)
|
||||
```
|
||||
|
||||
- By using a DataTemplate
|
||||
|
||||
|
@ -102,18 +117,32 @@ You can change this behavior with one of these values:
|
|||
ExampleInAppNotification.Show(inAppNotificationWithButtonsTemplate as DataTemplate);
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim inAppNotificationWithButtonsTemplate As Object
|
||||
Dim isTemplatePresent As Boolean = Resources.TryGetValue("InAppNotificationWithButtonsTemplate", inAppNotificationWithButtonsTemplate)
|
||||
|
||||
If isTemplatePresent AndAlso TypeOf inAppNotificationWithButtonsTemplate Is DataTemplate Then
|
||||
ExampleInAppNotification.Show(TryCast(inAppNotificationWithButtonsTemplate, DataTemplate))
|
||||
End If
|
||||
```
|
||||
|
||||
- By passing a second argument to the `Show()` method, you can set the duration of the notification (in milliseconds).
|
||||
|
||||
```csharp
|
||||
ExampleInAppNotification.Show("Some text.", 2000); // the notification will appear for 2 seconds
|
||||
```
|
||||
```vb
|
||||
ExampleInAppNotification.Show("Some text.", 2000) ' The notification will appear for 2 seconds
|
||||
```
|
||||
|
||||
- Call Dismiss to dismiss the notification
|
||||
|
||||
```csharp
|
||||
ExampleInAppNotification.Dismiss();
|
||||
```
|
||||
```vb
|
||||
ExampleInAppNotification.Dismiss()
|
||||
```
|
||||
|
||||
- Use EventArgs to find the dismiss kind of the InAppNotification in and Closed
|
||||
|
||||
|
@ -130,6 +159,17 @@ You can change this behavior with one of these values:
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub InAppNotification_OnClosing(ByVal sender As Object, ByVal e As InAppNotificationDismissingEventArgs)
|
||||
If e.DismissKind = InAppNotificationDismissKind.User Then
|
||||
' When the user asked to dismiss the notification
|
||||
End If
|
||||
|
||||
If e.DismissKind = InAppNotificationDismissKind.Timeout Then
|
||||
' When the notification is dismissed after timeout
|
||||
End If
|
||||
End Sub
|
||||
```
|
||||
|
||||
- The in-app notification control is designed to support multiple styles. The default style applied is the Microsoft Edge-like notification. Other styles have been added to the Toolkit so you can easily switch to another of your favorite In App Notification styles.
|
||||
|
||||
|
@ -159,9 +199,11 @@ You can change this behavior with one of these values:
|
|||
|
||||
- Apply the `Style`
|
||||
|
||||
```xaml
|
||||
<controls:InAppNotification x:Name="ExampleVSCodeInAppNotification" Style="{StaticResource VSCodeNotificationStyle}" />
|
||||
```
|
||||
```xaml
|
||||
<controls:InAppNotification
|
||||
x:Name="ExampleVSCodeInAppNotification"
|
||||
Style="{StaticResource VSCodeNotificationStyle}" />
|
||||
```
|
||||
|
||||
## Adding styles to Toolkit
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ Finally that the loading control appears, we must set the `IsLoading` property t
|
|||
```csharp
|
||||
LoadingControl.IsLoading = true;
|
||||
```
|
||||
```vb
|
||||
LoadingControl.IsLoading = true
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
@ -74,4 +77,3 @@ LoadingControl.IsLoading = true;
|
|||
## API
|
||||
|
||||
* [Loading source code](https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/Loading)
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: RangeSelector XAML Control
|
|||
author: nmetulev
|
||||
description: The RangeSelector Control is a Double Slider control that allows the user to select a sub-range of values from a larger range of possible values.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, RangeSelector, XAML Control, xaml, double slider
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# RangeSelector XAML Control
|
||||
|
@ -61,6 +64,17 @@ private void Selector_OnDragCompleted(object sender, DragCompletedEventArgs e)
|
|||
ScrollViewer.VerticalScrollMode = ScrollMode.Auto;
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub Selector_OnDragStarted(ByVal sender As Object, ByVal e As DragStartedEventArgs)
|
||||
ScrollViewer.HorizontalScrollMode = ScrollMode.Disabled
|
||||
ScrollViewer.VerticalScrollMode = ScrollMode.Disabled
|
||||
End Sub
|
||||
|
||||
Private Sub Selector_OnDragCompleted(ByVal sender As Object, ByVal e As DragCompletedEventArgs)
|
||||
ScrollViewer.HorizontalScrollMode = ScrollMode.Auto
|
||||
ScrollViewer.VerticalScrollMode = ScrollMode.Auto
|
||||
End Sub
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: SlidableListItem XAML Control
|
|||
author: nmetulev
|
||||
description: The SlidableListItem Control is a UI control that enables actions to be triggered by sliding the content left or right.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, SlidableListItem, XAML Control, xaml
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# SlidableListItem XAML Control
|
||||
|
@ -95,6 +98,21 @@ private void SlidableListItem_SwipeStatusChanged(SlidableListItem sender, SwipeS
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub SlidableListItem_SwipeStatusChanged(ByVal sender As SlidableListItem, ByVal args As SwipeStatusChangedEventArgs)
|
||||
If args.NewValue = SwipeStatus.Starting Then
|
||||
' Swiping starting
|
||||
ElseIf args.NewValue = SwipeStatus.Idle Then
|
||||
If args.OldValue = SwipeStatus.SwipingPassedLeftThreshold Then
|
||||
' Swiping to the left completed
|
||||
ElseIf args.OldValue = SwipeStatus.SwipingPassedRightThreshold Then
|
||||
' Swiping to the right completed
|
||||
Else
|
||||
' Swiping cancelled
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
```
|
||||
|
||||
If you use `SlidableListItem` in a `ListView` with the `ItemClick` event, you need to be aware the `ItemClick` event is triggered by default when the control has been swiped. If you don’t want this behavior you can set `IsPointerReleasedOnSwipingHandled` to `true` to suppress the `ItemClick` event. If you need more control you can instead check the `SwipeStatus` property in the `ItemClick` event. The following code shows how to do that:
|
||||
|
||||
|
@ -112,6 +130,18 @@ private void ListView_ItemClick(object sender, ItemClickEventArgs e)
|
|||
...
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Private Sub ListView_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
|
||||
Dim listView = TryCast(sender, ListView)
|
||||
Dim listViewItem = TryCast(listView.ContainerFromItem(e.ClickedItem), ListViewItem)
|
||||
Dim slidableListItem = TryCast(listViewItem.ContentTemplateRoot, SlidableListItem)
|
||||
|
||||
' Don't do anything unless the SwipeStatus is Idle.
|
||||
If slidableListItem.SwipeStatus <> SwipeStatus.Idle Then Return
|
||||
|
||||
...
|
||||
End Sub
|
||||
```
|
||||
|
||||
## <a name="swipe"></a> Moving to SwipeControl
|
||||
The Windows 10 Fall Creators Update SDK now includes the [SwipeControl](https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/swipe) control among other new controls and APIs. This is great news for the UWP Community Toolkit as it means that one of its most popular controls has a comparable counterpart in the Windows SDK and it is very easy to transition to the SwipeControl if you are already using the SlidableListItem.
|
||||
|
@ -156,4 +186,3 @@ There are several SlidableListItem properties that have no effect when the Slida
|
|||
## API
|
||||
|
||||
* [SlidableListItem source code](https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/SlidableListItem)
|
||||
|
||||
|
|
|
@ -93,6 +93,17 @@ Toolbar.CustomButtons.Add(new ToolbarButton
|
|||
});
|
||||
Toolbar.CustomButtons.Add(new ToolbarSeparator { Position = 2 });
|
||||
```
|
||||
```vb
|
||||
Dim button = Toolbar.GetDefaultButton(ButtonType.Headers)
|
||||
button.Visibility = Windows.UI.Xaml.Visibility.Collapsed
|
||||
Toolbar.CustomButtons.Add(New ToolbarButton With {
|
||||
.Name = "CustomButton",
|
||||
.Icon = New SymbolIcon(Symbol.ReportHacked),
|
||||
.Position = 1,
|
||||
.Activation = Sub(btn) Debug.WriteLine($"{btn.Name} Activated"),
|
||||
.ShortcutKey = Windows.System.VirtualKey.H})
|
||||
Toolbar.CustomButtons.Add(New ToolbarSeparator With {.Position = 2})
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Logical Tree Extensions
|
|||
author: nmetulev
|
||||
description: The LogicalTree extensions provide a collection of extensions methods for UI controls. It provides FrameworkElement extensions to aid in walking the logical tree of control structures.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Logical Tree, extentions
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Logical Tree Extensions
|
||||
|
@ -42,6 +45,30 @@ control = uiElement.FindParent<Grid>();
|
|||
// Retrieves the Content for the specified control from whatever its 'Content' Property may be.
|
||||
var content = uiElement.GetContentControl();
|
||||
```
|
||||
```vb
|
||||
' Include namespace to access extensions.
|
||||
Imports Microsoft.Toolkit.Uwp.UI.Extensions
|
||||
|
||||
' Find logical child control using its name.
|
||||
Dim control = uiElement.FindChildByName("MyTextBox")
|
||||
|
||||
' Find first logical child control of a specified type.
|
||||
control = uiElement.FindChild(Of ListView)()
|
||||
|
||||
// Retrieves the Content for the specified control from whatever its 'Content' Property may be.
|
||||
For Each child In uiElement.FindChildren(Of ListViewItem)()
|
||||
' ...
|
||||
Next
|
||||
|
||||
' Find first logical parent using its name.
|
||||
control = uiElement.FindParentByName("MyGrid")
|
||||
|
||||
' Find first logical parent control of a specified type.
|
||||
control = uiElement.FindParent(Of Grid)()
|
||||
|
||||
' Retrieves the Content for the specified control from whatever its 'Content' Property may be.
|
||||
Dim content = uiElement.GetContentControl()
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Visual Tree Extensions
|
|||
author: nmetulev
|
||||
description: The VisualTree extensions provide a collection of extensions methods for UI controls. It provides DependencyObject extensions to aid in using the VisualTreeHelper class.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Visual Tree, extentions
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Visual Tree Extensions
|
||||
|
@ -15,7 +18,7 @@ It provides [DependencyObject](https://docs.microsoft.com/uwp/api/Windows.UI.Xam
|
|||
|
||||
```csharp
|
||||
// Include namespace to access extensions.
|
||||
using Microsoft.Toolkit.Uwp.UI;
|
||||
using Microsoft.Toolkit.Uwp.UI.Extensions;
|
||||
|
||||
// Find visual descendant control using its name.
|
||||
var control = uiElement.FindDescendantByName("MyTextBox");
|
||||
|
@ -35,6 +38,26 @@ control = uiElement.FindAscendantByName("MyScrollViewer");
|
|||
// Find first visual ascendant control of a specified type.
|
||||
control = uiElement.FindAscendant<ScrollViewer>();
|
||||
```
|
||||
```vb
|
||||
' Include namespace to access extensions.
|
||||
Imports Microsoft.Toolkit.Uwp.UI.Extensions
|
||||
|
||||
' Find visual descendant control using its name.
|
||||
Dim control = uiElement.FindDescendantByName("MyTextBox")
|
||||
|
||||
' Find first visual descendant control of a specified type.
|
||||
control = uiElement.FindDescendant(Of ListView)()
|
||||
|
||||
' Find all visual descendant controls of the specified type.
|
||||
For Each child In uiElement.FindDescendants(Of ListViewItem)()
|
||||
' ...
|
||||
Next
|
||||
|
||||
' Find first visual ascendant control using its name.
|
||||
control = uiElement.FindAscendantByName("MyScrollViewer")
|
||||
' Find first visual ascendant control of a specified type.
|
||||
control = uiElement.FindAscendant(Of ScrollViewer)()
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: AdvancedCollectionView
|
|||
author: nmetulev
|
||||
description: The AdvancedCollectionView is a collection view implementation that support filtering, sorting and incremental loading. It's meant to be used in a viewmodel.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, AdvancedCollectionView
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# AdvancedCollectionView
|
||||
|
@ -52,7 +55,6 @@ var oc = new ObservableCollection<Person>
|
|||
};
|
||||
|
||||
// Set up the AdvancedCollectionView with live shaping enabled to filter and sort the original list
|
||||
|
||||
var acv = new AdvancedCollectionView(oc, true);
|
||||
|
||||
// Let's filter out the integers
|
||||
|
@ -72,6 +74,54 @@ person.Name = "Zaphod"; // Now a re-sort is triggered and person will be last in
|
|||
// AdvancedCollectionView can be bound to anything that uses collections.
|
||||
YourListView.ItemsSource = acv;
|
||||
```
|
||||
```vb
|
||||
Imports Microsoft.Toolkit.Uwp.UI
|
||||
|
||||
' Grab a sample type
|
||||
Public Class Person
|
||||
Public Property Name As String
|
||||
End Class
|
||||
|
||||
' Set up the original list with a few sample items
|
||||
Dim oc = New ObservableCollection(Of Person) From {
|
||||
New Person With {.Name = "Staff"},
|
||||
New Person With {.Name = "42"},
|
||||
New Person With {.Name = "Swan"},
|
||||
New Person With {.Name = "Orchid"},
|
||||
New Person With {.Name = "15"},
|
||||
New Person With {.Name = "Flame"},
|
||||
New Person With {.Name = "16"},
|
||||
New Person With {.Name = "Arrow"},
|
||||
New Person With {.Name = "Tempest"},
|
||||
New Person With {.Name = "23"},
|
||||
New Person With {.Name = "Pearl"},
|
||||
New Person With {.Name = "Hydra"},
|
||||
New Person With {.Name = "Lamp Post"},
|
||||
New Person With {.Name = "4"},
|
||||
New Person With {.Name = "Looking Glass"},
|
||||
New Person With {.Name = "8"}
|
||||
}
|
||||
|
||||
' Set up the AdvancedCollectionView with live shaping enabled to filter and sort the original list
|
||||
Dim acv = New AdvancedCollectionView(oc, True)
|
||||
|
||||
' Let's filter out the integers
|
||||
Dim nul As Integer
|
||||
acv.Filter = Function(x) Not Integer.TryParse((CType(x, Person)).Name, nul)
|
||||
|
||||
' And sort ascending by the property "Name"
|
||||
acv.SortDescriptions.Add(New SortDescription("Name", SortDirection.Ascending))
|
||||
|
||||
' Let's add a Person to the observable collection
|
||||
Dim person = New Person With {.Name = "Aardvark"}
|
||||
oc.Add(person)
|
||||
|
||||
' Our added person is now at the top of the list, but if we rename this person, we can trigger a re-sort
|
||||
person.Name = "Zaphod" ' Now a re-sort is triggered and person will be last in the list
|
||||
|
||||
' AdvancedCollectionView can be bound to anything that uses collections.
|
||||
YourListView.ItemsSource = acv
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
|
@ -83,7 +133,7 @@ YourListView.ItemsSource = acv;
|
|||
| Count | int | Get the count of items |
|
||||
| CurrentItem | object | Gets or sets the current item |
|
||||
| CurrentPosition | int | Gets the position of current item |
|
||||
| Filter | Predicate<object> | Gets or sets the predicate used to filter the visisble items |
|
||||
| Filter | Predicate<object> | Gets or sets the predicate used to filter the visible items |
|
||||
| HasMoreItems | bool | Gets a value indicating whether the source has more items |
|
||||
| IsCurrentAfterLast | bool | Gets a value indicating whether the current item is after the last visible item |
|
||||
| IsCurrentBeforeFirst | bool | Gets a value indicating whether the current item is before the first visible item |
|
||||
|
@ -102,7 +152,7 @@ YourListView.ItemsSource = acv;
|
|||
| Contains(Object) | bool | Returns `true` if the given item contained in CollectionView |
|
||||
| B(float, string) | int | Description |
|
||||
| DeferRefresh() | IDisposable | Stops refreshing until it is disposed |
|
||||
| IndexOf(Object) | int | Return idex of an item |
|
||||
| IndexOf(Object) | int | Return index of an item |
|
||||
| Insert(Int32, Object) | void | Insert an item in a particular place |
|
||||
| LoadMoreItemsAsync(UInt32) | IAsyncOperation<[LoadMoreItemsResult](https://docs.microsoft.com/uwp/api/Windows.UI.Xaml.Data.LoadMoreItemsResult)> | Load more items from the source |
|
||||
| MoveCurrentTo(Object) | bool | Move current index to item. Returns success of operation |
|
||||
|
@ -143,6 +193,13 @@ using (acv.DeferRefresh())
|
|||
}
|
||||
} // acv.Refresh() gets called here
|
||||
```
|
||||
```vb
|
||||
Using acv.DeferRefresh()
|
||||
For i = 0 To 500 - 1
|
||||
acv.Add(New Person With {.Name = "defer"})
|
||||
Next
|
||||
End Using ' acv.Refresh() gets called here
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Background Task Helper
|
|||
author: nmetulev
|
||||
description: The Background Task Helper helps users interacting with background tasks in an easier manner.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Background Task Helper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Background Task Helper
|
||||
|
@ -17,6 +20,12 @@ using Microsoft.Toolkit.Uwp;
|
|||
BackgroundTaskRegistration registered = BackgroundTaskHelper.Register(typeof(BackgroundTaskClass), new TimeTrigger(15, true));
|
||||
BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("TaskName", "TaskEntryPoint", new TimeTrigger(15, true));
|
||||
```
|
||||
```vb
|
||||
Imports Microsoft.Toolkit.Uwp
|
||||
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register(GetType(BackgroundTaskClass), New TimeTrigger(15, True))
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register("TaskName", "TaskEntryPoint", New TimeTrigger(15, True))
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
|
@ -72,6 +81,32 @@ BackgroundTaskRegistration registered =
|
|||
new SystemCondition(SystemConditionType.InternetAvailable),
|
||||
new SystemCondition(SystemConditionType.UserPresent));
|
||||
```
|
||||
```vb
|
||||
' Be sure to include the Imports at the top of the file:
|
||||
Imports Microsoft.Toolkit.Uwp
|
||||
Imports Windows.ApplicationModel.Background
|
||||
|
||||
' Register a normal, seperate process, background task
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register("TaskName", "TaskEntryPoint", New TimeTrigger(15, True))
|
||||
|
||||
' This can also be written using the overload of Register with Type parameter.
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register(GetType(BackgroundTaskClass), New TimeTrigger(15, True))
|
||||
|
||||
' With condition
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register(GetType(BackgroundTaskClass),
|
||||
New TimeTrigger(15, True),
|
||||
False,
|
||||
True,
|
||||
New SystemCondition(SystemConditionType.InternetAvailable))
|
||||
|
||||
' 2 or more conditions
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register(GetType(BackgroundTaskClass),
|
||||
New TimeTrigger(15, True),
|
||||
False,
|
||||
True,
|
||||
New SystemCondition(SystemConditionType.InternetAvailable),
|
||||
New SystemCondition(SystemConditionType.UserPresent))
|
||||
```
|
||||
|
||||
### Using Single-Process Model
|
||||
|
||||
|
@ -91,6 +126,14 @@ using Windows.ApplicationModel.Background;
|
|||
// Register a single process background task (Anniversary Update and later ONLY)
|
||||
BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("Name of the Background Task", new TimeTrigger(15, true));
|
||||
```
|
||||
```vb
|
||||
' Be sure to include the imports at the top of the file:
|
||||
Imports Microsoft.Toolkit.Uwp
|
||||
Imports Windows.ApplicationModel.Background
|
||||
|
||||
' Register a single process background task (Anniversary Update and later ONLY)
|
||||
Dim registered As BackgroundTaskRegistration = BackgroundTaskHelper.Register("Name of the Background Task", New TimeTrigger(15, True))
|
||||
```
|
||||
|
||||
The other difference between SPM and MPM is that in SPM, you have to handle your Background Tasks inside the `OnBackgroundActivated` event of `App.xaml.cs` class.
|
||||
Here is an example of how to handle Background Tasks in SPM.
|
||||
|
@ -113,6 +156,20 @@ protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
|
|||
deferral.Complete();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Protected Overrides Sub OnBackgroundActivated(ByVal args As BackgroundActivatedEventArgs)
|
||||
MyBase.OnBackgroundActivated(args)
|
||||
|
||||
Dim deferral = args.TaskInstance.GetDeferral()
|
||||
|
||||
Select Case args.TaskInstance.Task.Name
|
||||
Case "Name of the Background Task"
|
||||
New TestBackgroundTask().Run(args.TaskInstance)
|
||||
End Select
|
||||
|
||||
deferral.Complete()
|
||||
End Sub
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: BluetoothLEHelper
|
|||
author: nmetulev
|
||||
description: The BluetoothLEHelper class provides functionality to easily enumerate, connect to and interact with Bluetooth LE Peripherals.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, BluetoothLEHelper, bluetooth le, bluetooth
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# BluetoothLEHelper
|
||||
|
@ -123,6 +126,29 @@ if (BluetoothLEHelper.IsBluetoothLESupported)
|
|||
var services = device.Services;
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Get a local copy of the context for easier reading
|
||||
Dim bluetoothLEHelper As BluetoothLEHelper = BluetoothLEHelper.Context
|
||||
|
||||
' check if BluetoothLE APIs are available
|
||||
If BluetoothLEHelper.IsBluetoothLESupported Then
|
||||
' Start the Enumeration
|
||||
bluetoothLEHelper.StartEnumeration()
|
||||
|
||||
' At this point the user needs to select a device they want to connect to. This can be done by
|
||||
' creating a ListView and binding the bluetoothLEHelper collection to it. Once a device is found,
|
||||
' the Connect() method can be called to connect to the device and start interacting with its services
|
||||
|
||||
' Connect to a device if your choice
|
||||
Dim device As ObservableBluetoothLEDevice = bluetoothLEHelper.BluetoothLeDevices(<Device you choose>)
|
||||
Await device.ConnectAsync()
|
||||
|
||||
' At this point the device is connected and the Services property is populated.
|
||||
|
||||
' See all the services
|
||||
Dim services = device.Services
|
||||
End If
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Colors Helper
|
|||
author: nmetulev
|
||||
description: The Colors Helper lets users convert colors from text names, HTML hex, HSV, or HSL to Windows UI Colors
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Colors Helper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Colors Helper
|
||||
|
@ -24,6 +27,19 @@ Windows.UI.Color myColor = ColorHelper.ToColor("#ff3a4ab0");
|
|||
// Given a color name, lets convert it to a Windows Color
|
||||
Windows.UI.Color redColor = "Red".ToColor();
|
||||
```
|
||||
```vb
|
||||
' Be sure to include the imports at the top of the file:
|
||||
Imports Microsoft.Toolkit.Uwp
|
||||
|
||||
' Given an HTML color, lets convert it to a Windows Color
|
||||
Dim color As Windows.UI.Color = ColorHelper.ToColor("#3a4ab0")
|
||||
|
||||
' Also works with an Alpha code
|
||||
Dim myColor As Windows.UI.Color = ColorHelper.ToColor("#ff3a4ab0")
|
||||
|
||||
' Given a color name, lets convert it to a Windows Color
|
||||
Dim redColor As Windows.UI.Color = "Red".ToColor()
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: DeepLinkParser
|
|||
author: nmetulev
|
||||
description: Provides a way to create, Dictionary<string,string> - inheriting object that provides an additional .Root property to pull the base path of the URI
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, DeepLinkParser
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# DeepLinkParser
|
||||
|
@ -45,6 +48,19 @@ if (e.PrelaunchActivated == false)
|
|||
}
|
||||
...
|
||||
```
|
||||
```vb
|
||||
If e.PrelaunchActivated = False Then
|
||||
If rootFrame.Content Is Nothing Then
|
||||
Dim parser = DeepLinkParser.Create(args)
|
||||
If parser("username") = "John Doe" Then
|
||||
' do work here
|
||||
End If
|
||||
|
||||
If parser.Root = "Signup" Then
|
||||
rootFrame.Navigate(GetType(Signup))
|
||||
End If
|
||||
...
|
||||
```
|
||||
|
||||
## CollectionFormingDeepLinkParser
|
||||
|
||||
|
@ -54,7 +70,7 @@ The [CollectionFormingDeepLinkParser Class](https://docs.microsoft.com/dotnet/ap
|
|||
|
||||
in OnLaunched of App.xaml.cs:
|
||||
|
||||
```c#
|
||||
```csharp
|
||||
if (e.PrelaunchActivated == false)
|
||||
{
|
||||
if (rootFrame.Content == null)
|
||||
|
@ -69,6 +85,21 @@ if (e.PrelaunchActivated == false)
|
|||
var preferences = parser["pref"].Split(','); // now a string[] of all 'pref' querystring values passed in URI
|
||||
rootFrame.Navigate(typeof(Signup));
|
||||
}
|
||||
...
|
||||
```
|
||||
```vb
|
||||
If e.PrelaunchActivated = False Then
|
||||
If rootFrame.Content Is Nothing Then
|
||||
Dim parser = CollectionFormingDeepLinkParser.Create(args)
|
||||
If parser("username") = "John Doe" Then
|
||||
' do work here
|
||||
End If
|
||||
|
||||
If parser.Root = "Signup" Then
|
||||
Dim preferences = parser("pref").Split(","c) ' now a string[] of all 'pref' querystring values passed in URI
|
||||
rootFrame.Navigate(GetType(Signup))
|
||||
End If
|
||||
...
|
||||
```
|
||||
|
||||
Both of these are createable using a `.Create(IActivatedEventArgs)` method. Should you wish to create one in a different manner, the default constructor is `protected` so inheriting from either of these can provide extensibility.
|
||||
|
@ -81,17 +112,24 @@ The [QueryParameterCollection](https://docs.microsoft.com/dotnet/api/microsoft.t
|
|||
### Example
|
||||
|
||||
```csharp
|
||||
var myUrl = http://microsoft.com/?user=fooUser&email=fooUser@outlook.com&firstName=John&lastName=Doe
|
||||
var myUrl = "http://microsoft.com/?user=fooUser&email=fooUser@outlook.com&firstName=John&lastName=Doe"
|
||||
var paramCollection = new QueryParameterCollection(myUrl);
|
||||
foreach (var pair in paramCollection)
|
||||
{
|
||||
Console.WriteLine($"{pair.Key} - {pair.Value}");
|
||||
Console.WriteLine($"{pair.Key} - {pair.Value}");
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim myUrl = "http://microsoft.com/?user=fooUser&email=fooUser@outlook.com&firstName=John&lastName=Doe"
|
||||
Dim paramCollection = New QueryParameterCollection(myUrl)
|
||||
For Each pair In paramCollection
|
||||
Console.WriteLine($"{pair.Key} - {pair.Value}")
|
||||
Next
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
```csharp
|
||||
```
|
||||
user - fooUser
|
||||
email - fooUser@outlook.com
|
||||
firstname - John
|
||||
|
|
|
@ -3,6 +3,9 @@ title: DispatcherHelper
|
|||
author: nmetulev
|
||||
description: The DispatcherHelper class enables easy interaction with CoreDispatcher, mainly in the case of executing a block of code on the UI thread from a non-UI thread.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, DispatcherHelper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# DispatcherHelper
|
||||
|
@ -30,6 +33,15 @@ await CoreApplication.MainView.Dispatcher.AwaitableRunAsync<T>( () =>
|
|||
|
||||
});
|
||||
```
|
||||
```vb
|
||||
DispatcherHelper.ExecuteOnUIThreadAsync(Of T)(Function()
|
||||
' Code to execute on main window's UI thread
|
||||
End Function)
|
||||
|
||||
Await CoreApplication.MainView.Dispatcher.AwaitableRunAsync(Of T)(Function()
|
||||
|
||||
End Function)
|
||||
``
|
||||
|
||||
## Methods
|
||||
|
||||
|
@ -68,6 +80,22 @@ returnedFromUIThread = await CoreApplication.MainView.Dispatcher.AwaitableRunAsy
|
|||
return 1;
|
||||
});
|
||||
```
|
||||
```vb
|
||||
' Executing from a non-UI thread with helper method
|
||||
Dim returnedFromUIThread As Integer = Await DispatcherHelper.ExecuteOnUIThreadAsync(Of Integer)(Function()
|
||||
' Code to execute on main window's UI thread
|
||||
NormalTextBlock.Text = "Updated from a random thread!"
|
||||
Return 1
|
||||
End Function)
|
||||
|
||||
' returnedFromUIThread now is 1, execution can go on from the non-UI thread
|
||||
|
||||
' Or update it manually via the Extension method for CoreDispatcher
|
||||
returnedFromUIThread = Await CoreApplication.MainView.Dispatcher.AwaitableRunAsync(Of Integer)(Function()
|
||||
NormalTextBlock.Text = "Updated from a random thread with extension method!"
|
||||
Return 1
|
||||
End Function)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: HttpHelper
|
|||
author: nmetulev
|
||||
description: HttpHelper is a UWP Community Toolkit helper class used to assist in common http and networking scenarios.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, HttpHelper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# HttpHelper
|
||||
|
@ -10,15 +13,19 @@ keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, HttpHelper
|
|||
> [!WARNING]
|
||||
(This API is obsolete and will be removed in the future. Please use [System.Net.Http.HttpClient](https://msdn.microsoft.com/library/system.net.http.httpclient(v=vs.110).aspx) or [Windows.Web.Http.HttpClient](https://docs.microsoft.com/uwp/api/Windows.Web.Http.HttpClient) directly)
|
||||
|
||||
The [HttpHelper](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.httphelper)
|
||||
represents an HTTP request message including headers.
|
||||
The [HttpHelper](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.httphelper) represents an HTTP request message including headers.
|
||||
|
||||
## Syntax
|
||||
|
||||
```csharp
|
||||
var request = new HttpHelperRequest(new Uri("URI"), HttpMethod.Post)
|
||||
var request = new HttpHelperRequest(new Uri("URI"), HttpMethod.Post);
|
||||
|
||||
var response = await HttpHelper.Instance.SendRequestAsync(request)
|
||||
var response = await HttpHelper.Instance.SendRequestAsync(request);
|
||||
```
|
||||
```vb
|
||||
Private request = New HttpHelperRequest(New Uri("URI"), HttpMethod.Post)
|
||||
|
||||
Private response = Await HttpHelper.Instance.SendRequestAsync(request)
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
@ -55,6 +62,13 @@ using (var request = new HttpHelperRequest(new Uri(twitterUrl), HttpMethod.Post)
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Using request = New HttpHelperRequest(New Uri(twitterUrl), HttpMethod.Post)
|
||||
Using response = Await HttpHelper.Instance.SendRequestAsync(request)
|
||||
Return Await response.GetTextResultAsync()
|
||||
End Using
|
||||
End Using
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: HttpHelperRequest
|
|||
author: nmetulev
|
||||
description: HttpHelperRequest is a UWP Community Toolkit helper class used with the HttpHelper class to create http requests.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, HttpHelperRequest
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# HttpHelperRequest
|
||||
|
@ -13,11 +16,12 @@ or [Windows.Web.Http.HttpRequestMessage](https://docs.microsoft.com/uwp/api/wind
|
|||
|
||||
The [HttpHelperRequest](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.httphelperrequest) represents an HTTP request message including headers.
|
||||
|
||||
## Syntax
|
||||
|
||||
```csharp
|
||||
var request = new HttpHelperRequest(uri, HttpMethod.Get);
|
||||
```
|
||||
```vb
|
||||
Dim request = New HttpHelperRequest(uri, HttpMethod.[Get])
|
||||
```
|
||||
|
||||
## Constructors
|
||||
|
||||
|
@ -60,6 +64,10 @@ An app starts by using one of the **HttpHelperRequest** constructors to create a
|
|||
var request = new HttpHelperRequest(uri, HttpMethod.Get);
|
||||
request.Headers.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams);
|
||||
```
|
||||
```vb
|
||||
Dim request = New HttpHelperRequest(uri, HttpMethod.[Get])
|
||||
request.Headers.Authorization = New Windows.Web.Http.Headers.HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: HttpHelperResponse
|
|||
author: nmetulev
|
||||
description: HttpHelperResponse is a UWP Community Toolkit helper class used with the HttpHelper class to read http responses.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, HttpHelperResponse
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# HttpHelperResponse
|
||||
|
@ -19,9 +22,13 @@ or [Windows.Web.Http.HttpResponseMessage](https://docs.microsoft.com/uwp/api/Win
|
|||
using (HttpHelperResponse response = await HttpHelper.Instance.SendRequestAsync(request))
|
||||
{
|
||||
await response.GetTextResultAsync();
|
||||
response.Dispose();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Using response = Await HttpHelper.Instance.SendRequestAsync(request)
|
||||
Await response.GetTextResultAsync()
|
||||
End Using
|
||||
```
|
||||
|
||||
## Constructors
|
||||
|
||||
|
@ -65,6 +72,13 @@ using (var request = new HttpHelperRequest(new Uri(twitterUrl), HttpMethod.Post)
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Using request = New HttpHelperRequest(New Uri(twitterUrl), HttpMethod.Post)
|
||||
Using response = Await HttpHelper.Instance.SendRequestAsync(request)
|
||||
Return Await response.GetTextResultAsync()
|
||||
End Using
|
||||
End Using
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: ImageCache
|
|||
author: nmetulev
|
||||
description: The ImageCache provides methods and tools to cache images in a temporary local folder.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, ImageCache
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# ImageCache
|
||||
|
@ -21,11 +24,26 @@ ImageCache.Instance.MaxMemoryCacheCount = 100;
|
|||
var distantUri = new Uri("http://www.myserver.com/image.jpg");
|
||||
|
||||
// Load a specific image from the cache. If the image is not in the cache, ImageCache will try to download and store it
|
||||
var bitmapImage = await ImageCache.Instance.GetFromCacheAsync(distantUri));
|
||||
var bitmapImage = await ImageCache.Instance.GetFromCacheAsync(distantUri);
|
||||
|
||||
// Clear the cache. Please note that you can provide a parameter to define a timespan from now to select cache entries to delete.
|
||||
await ImageCache.Instance.ClearAsync();
|
||||
```
|
||||
```vb
|
||||
' Set cache duration
|
||||
ImageCache.Instance.CacheDuration = TimeSpan.FromHours(24)
|
||||
|
||||
' Enable in-memory caching
|
||||
ImageCache.Instance.MaxMemoryCacheCount = 100
|
||||
|
||||
Dim distantUri = New Uri("http://www.myserver.com/image.jpg")
|
||||
|
||||
' Load a specific image from the cache. If the image is not in the cache, ImageCache will try to download and store it
|
||||
Dim bitmapImage = Await ImageCache.Instance.GetFromCacheAsync(distantUri)
|
||||
|
||||
' Clear the cache. Please note that you can provide a parameter to define a timespan from now to select cache entries to delete.
|
||||
Await ImageCache.Instance.ClearAsync()
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Incremental Loading Collection Helpers
|
|||
author: nmetulev
|
||||
description: The IncrementalLoadingCollection helpers greatly simplify the definition and usage of collections whose items can be loaded incrementally only when needed by the view
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, IncrementalLoadingCollection
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Incremental Loading Collection Helpers
|
||||
|
@ -77,6 +80,39 @@ public class PeopleSource : IIncrementalSource<Person>
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Be sure to include the using at the top of the file:
|
||||
'Imports Microsoft.Toolkit.Uwp
|
||||
|
||||
Public Class Person
|
||||
|
||||
Public Property Name As String
|
||||
End Class
|
||||
|
||||
Public Class PeopleSource
|
||||
Implements IIncrementalSource(Of Person)
|
||||
|
||||
Private ReadOnly people As List(Of Person)
|
||||
|
||||
Public Sub New()
|
||||
' Creates an example collection.
|
||||
people = New List(Of Person)()
|
||||
For i As Integer = 1 To 200
|
||||
Dim p = New Person With {.Name = "Person " & i}
|
||||
people.Add(p)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Public Async Function GetPagedItemsAsync(pageIndex As Integer, pageSize As Integer, Optional cancellationToken As CancellationToken = Nothing) As Task(Of IEnumerable(Of Person)) Implements Microsoft.Toolkit.Collections.IIncrementalSource(Of Person).GetPagedItemsAsync
|
||||
' Gets items from the collection according to pageIndex and pageSize parameters.
|
||||
Dim result = (From p In people Select p).Skip(pageIndex * pageSize).Take(pageSize)
|
||||
|
||||
' Simulates a longer request...
|
||||
Await Task.Delay(1000)
|
||||
Return result
|
||||
End Function
|
||||
End Class
|
||||
```
|
||||
|
||||
The *GetPagedItemsAsync* method is invoked everytime the view need to show more items.
|
||||
|
||||
|
@ -86,6 +122,10 @@ The *GetPagedItemsAsync* method is invoked everytime the view need to show more
|
|||
var collection = new IncrementalLoadingCollection<PeopleSource, Person>();
|
||||
PeopleListView.ItemsSource = collection;
|
||||
```
|
||||
```vb
|
||||
Dim collection = New IncrementalLoadingCollection(Of PeopleSource, Person)()
|
||||
PeopleListView.ItemsSource = collection
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: NetworkHelper
|
|||
author: nmetulev
|
||||
description: he NetworkHelper class provides functionality to monitor changes in network connection and allows users to query for network information without additional lookups.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, NetworkHelper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# NetworkHelper
|
||||
|
@ -61,20 +64,43 @@ if (NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection)
|
|||
// Get precise connection type
|
||||
switch(NetworkHelper.Instance.ConnectionInformation.ConnectionType)
|
||||
{
|
||||
case ConnectionType.Ethernet:
|
||||
// Ethernet
|
||||
break;
|
||||
case ConnectionType.WiFi:
|
||||
// WiFi
|
||||
break;
|
||||
case ConnectionType.Data:
|
||||
// Data
|
||||
break;
|
||||
case ConnectionType.Unknown:
|
||||
// Unknown
|
||||
break;
|
||||
case ConnectionType.Ethernet:
|
||||
// Ethernet
|
||||
break;
|
||||
case ConnectionType.WiFi:
|
||||
// WiFi
|
||||
break;
|
||||
case ConnectionType.Data:
|
||||
// Data
|
||||
break;
|
||||
case ConnectionType.Unknown:
|
||||
// Unknown
|
||||
break;
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Detect if Internet can be reached
|
||||
If NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable Then
|
||||
...
|
||||
End If
|
||||
|
||||
' Detect if the connection is metered
|
||||
If NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection Then
|
||||
...
|
||||
End If
|
||||
|
||||
' Get precise connection type
|
||||
Select Case NetworkHelper.Instance.ConnectionInformation.ConnectionType
|
||||
Case ConnectionType.Ethernet
|
||||
' Ethernet
|
||||
Case ConnectionType.WiFi
|
||||
' WiFi
|
||||
Case ConnectionType.Data
|
||||
' Data
|
||||
Case ConnectionType.Unknown
|
||||
' Unknown
|
||||
End Select
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Object Storage
|
|||
author: nmetulev
|
||||
description: The Object Storage Helper will help you handle storage of generic objects within UWP applications, both locally and across all devices (roaming).
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Object Storage, local storage, roaming storage
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Object Storage
|
||||
|
@ -79,6 +82,42 @@ var o = new MyLargeObject
|
|||
};
|
||||
await helper.SaveFileAsync(keySimpleObject, o);
|
||||
```
|
||||
```vb
|
||||
Dim helper = New LocalObjectStorageHelper()
|
||||
|
||||
' Read simple objects
|
||||
Dim keySimpleObject As String = "simple"
|
||||
If helper.KeyExists(keySimpleObject) Then
|
||||
Dim result As String = helper.Read(Of String)(keySimpleObject)
|
||||
End If
|
||||
|
||||
' Read simple objects in a composite
|
||||
Dim keyCompositeObject As String = "composite"
|
||||
If helper.KeyExists(keyCompositeObject, keySimpleObject) Then
|
||||
Dim result As String = helper.Read(Of String)(keyCompositeObject, keySimpleObject)
|
||||
End If
|
||||
|
||||
' Save simple objects
|
||||
helper.Save(keySimpleObject, 47)
|
||||
|
||||
' Save simple objects in a composite
|
||||
Dictionary(Of String, Object)() simpleObjects = New Dictionary(Of String, Object)()
|
||||
simpleObjects.add("simpleObjectValueOne", 47)
|
||||
simpleObjects.add("simpleObjectValueTwo", "hello!")
|
||||
helper.Save(keyCompositeObject, simpleObjects)
|
||||
|
||||
' Read complex/large objects
|
||||
Dim keyLargeObject As String = "large"
|
||||
If Await helper.FileExistsAsync(keyLargeObject) Then
|
||||
Dim result = Await helper.ReadFileAsync(Of MyLargeObject)(keyLargeObject)
|
||||
End If
|
||||
|
||||
' Save complex/large objects
|
||||
Dim o = New MyLargeObject With {
|
||||
...
|
||||
}
|
||||
Await helper.SaveFileAsync(keySimpleObject, o)
|
||||
```
|
||||
|
||||
### Roaming Storage
|
||||
|
||||
|
@ -125,6 +164,42 @@ var o = new MyLargeObject
|
|||
};
|
||||
await helper.SaveFileAsync(keySimpleObject, o);
|
||||
```
|
||||
```vb
|
||||
Dim helper = New RoamingObjectStorageHelper()
|
||||
|
||||
' Read simple objects
|
||||
Dim keySimpleObject As String = "simple"
|
||||
If helper.KeyExists(keySimpleObject) Then
|
||||
Dim result As String = helper.Read(Of String)(keySimpleObject)
|
||||
End If
|
||||
|
||||
' Read simple objects in a composite
|
||||
Dim keyCompositeObject As String = "composite"
|
||||
If helper.KeyExists(keyCompositeObject, keySimpleObject) Then
|
||||
Dim result As String = helper.Read(Of String)(keyCompositeObject, keySimpleObject)
|
||||
End If
|
||||
|
||||
' Save simple objects
|
||||
helper.Save(keySimpleObject, 47)
|
||||
|
||||
' Save simple objects in a composite
|
||||
Dictionary(Of String, Object)() simpleObjects = New Dictionary(Of String, Object)()
|
||||
simpleObjects.add("simpleObjectValueOne", 47)
|
||||
simpleObjects.add("simpleObjectValueTwo", "hello!")
|
||||
helper.Save(keyCompositeObject, simpleObjects)
|
||||
|
||||
' Read complex/large objects
|
||||
Dim keyLargeObject As String = "large"
|
||||
If Await helper.FileExistsAsync(keyLargeObject) Then
|
||||
Dim result = Await helper.ReadFileAsync(Of MyLargeObject)(keyLargeObject)
|
||||
End If
|
||||
|
||||
' Save complex/large objects
|
||||
Dim o = New MyLargeObject With {
|
||||
...
|
||||
}
|
||||
Await helper.SaveFileAsync(keySimpleObject, o)
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Print Helper
|
|||
author: nmetulev
|
||||
description: The PrintHelper is a UWP Community Toolkit helper class that enables the rendering of a framework element per page for printing purposes
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, PrintHelper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Print Helper
|
||||
|
@ -35,6 +38,13 @@ printHelper.AddFrameworkElementToPrint(frameworkElement);
|
|||
|
||||
await printHelper.ShowPrintUIAsync("Title");
|
||||
```
|
||||
```vb
|
||||
Dim printHelper = New PrintHelper(container)
|
||||
|
||||
printHelper.AddFrameworkElementToPrint(frameworkElement)
|
||||
|
||||
Await printHelper.ShowPrintUIAsync("Title")
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
|
@ -96,6 +106,36 @@ private async void PrintHelper_OnPrintFailed()
|
|||
await dialog.ShowAsync();
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Create a new PrintHelper instance
|
||||
' "container" is a XAML panel that will be used to host printable control.
|
||||
' It needs to be in your visual tree but can be hidden with Opacity = 0
|
||||
Dim printHelper = New PrintHelper(container)
|
||||
|
||||
' Add controls that you want to print
|
||||
printHelper.AddFrameworkElementToPrint(Await PrepareWebViewForPrintingAsync())
|
||||
|
||||
' Connect to relevant events
|
||||
printHelper.OnPrintFailed += PrintHelper_OnPrintFailed
|
||||
printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded
|
||||
|
||||
' Start printing process
|
||||
Await printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App")
|
||||
|
||||
' Event handlers
|
||||
|
||||
Private Async Sub PrintHelper_OnPrintSucceeded()
|
||||
printHelper.Dispose()
|
||||
Dim dialog = New MessageDialog("Printing done.")
|
||||
Await dialog.ShowAsync()
|
||||
End Sub
|
||||
|
||||
Private Async Sub PrintHelper_OnPrintFailed()
|
||||
printHelper.Dispose()
|
||||
Dim dialog = New MessageDialog("Printing failed.")
|
||||
Await dialog.ShowAsync()
|
||||
End Sub
|
||||
```
|
||||
|
||||
**Direct print example:**
|
||||
|
||||
|
@ -107,6 +147,14 @@ var printHelper = new PrintHelper(container);
|
|||
// Start printing process
|
||||
await printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", true);
|
||||
```
|
||||
```vb
|
||||
' Create a new PrintHelper instance
|
||||
' "container" is a XAML panel that will be used to get the list of printable controls.
|
||||
Dim printHelper = New PrintHelper(container)
|
||||
|
||||
' Start printing process
|
||||
Await printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", True)
|
||||
```
|
||||
|
||||
**Using custom default settings:**
|
||||
|
||||
|
@ -124,6 +172,20 @@ defaultPrintHelperOptions.Orientation = PrintOrientation.Landscape;
|
|||
// "container" is a XAML panel that will be used to get the list of printable controls.
|
||||
var printHelper = new PrintHelper(container, defaultPrintHelperOptions);
|
||||
```
|
||||
```vb
|
||||
' Create a new PrintHelperOptions instance
|
||||
Dim defaultPrintHelperOptions = New PrintHelperOptions()
|
||||
|
||||
' Add options that you want to be displayed on the print dialog
|
||||
defaultPrintHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation)
|
||||
|
||||
' Set preselected settings
|
||||
defaultPrintHelperOptions.Orientation = PrintOrientation.Landscape
|
||||
|
||||
' Create a new PrintHelper instance
|
||||
' "container" is a XAML panel that will be used to get the list of printable controls.
|
||||
Dim printHelper = New PrintHelper(container, defaultPrintHelperOptions)
|
||||
```
|
||||
|
||||
**Using custom settings for one print job:**
|
||||
|
||||
|
@ -145,6 +207,24 @@ printHelperOptions.Orientation = PrintOrientation.Landscape;
|
|||
// Start printing process
|
||||
await _printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", printHelperOptions);
|
||||
```
|
||||
```vb
|
||||
' Create a new PrintHelper instance
|
||||
' "container" is a XAML panel that will be used to get the list of printable controls.
|
||||
' "defaultPrintHelperOptions" is a PrintHelperOptions instance that will be used to get the default options for printing.
|
||||
Dim printHelper = New PrintHelper(container, defaultPrintHelperOptions)
|
||||
|
||||
' Create a new PrintHelperOptions instance
|
||||
Dim printHelperOptions = New PrintHelperOptions()
|
||||
|
||||
' Add options that you want to be displayed on the print dialog
|
||||
printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation)
|
||||
|
||||
' Set preselected settings
|
||||
printHelperOptions.Orientation = PrintOrientation.Landscape
|
||||
|
||||
' Start printing process
|
||||
Await _printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", printHelperOptions)
|
||||
```
|
||||
|
||||
**Print a list with each item on a separate page with static header and page number:**
|
||||
|
||||
|
@ -186,6 +266,31 @@ foreach (var item in PrintSampleItems)
|
|||
// Start printing process
|
||||
await printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", printHelperOptions);
|
||||
```
|
||||
```vb
|
||||
Dim printHelper = New PrintHelper(container)
|
||||
Dim pageNumber = 0
|
||||
For Each item In PrintSampleItems
|
||||
Dim grid = New Grid()
|
||||
grid.RowDefinitions.Add(New RowDefinition() With {.Height = GridLength.Auto})
|
||||
grid.RowDefinitions.Add(New RowDefinition() With {.Height = New GridLength(1, GridUnitType.Star)})
|
||||
grid.RowDefinitions.Add(New RowDefinition() With {.Height = GridLength.Auto})
|
||||
Dim header = New TextBlock With {.Text = "UWP Community Toolkit Sample App - Print Helper - Custom Print", .Margin = New Thickness(0, 0, 0, 20)}
|
||||
Grid.SetRow(header, 0)
|
||||
grid.Children.Add(header)
|
||||
Dim cont = New ContentControl()
|
||||
cont.ContentTemplate = TryCast(Resources("CustomPrintTemplate"), DataTemplate)
|
||||
cont.DataContext = item
|
||||
Grid.SetRow(cont, 1)
|
||||
grid.Children.Add(cont)
|
||||
pageNumber += 1
|
||||
Dim footer = New TextBlock With {.Text = String.Format("page {0}", pageNumber), .Margin = New Thickness(0, 20, 0, 0)}
|
||||
Grid.SetRow(footer, 2)
|
||||
grid.Children.Add(footer)
|
||||
printHelper.AddFrameworkElementToPrint(grid)
|
||||
Next
|
||||
|
||||
Await printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App", printHelperOptions)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: StorageFileHelper
|
|||
author: nmetulev
|
||||
description: The StorageFileHelper is a static utility class that provides functions to help with reading and writing of text and bytes to the disk. These functions are all wrapped into Async tasks.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, StorageFileHelper
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# StorageFileHelper
|
||||
|
@ -40,6 +43,35 @@ bool isFileNameValid = StorageFileHelper.IsFileNameValid("appFilename.txt");
|
|||
// Check if a file path is valid or not
|
||||
bool isFilePathValid = StorageFileHelper.IsFilePathValid("folder/appFilename.txt");
|
||||
```
|
||||
```vb
|
||||
' NOTE This must be used from an async function
|
||||
Dim myText As String = "Great information that the users wants to keep"
|
||||
Dim localFolder As StorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder
|
||||
|
||||
' Save some text to a file named appFilename.txt (in the local cache folder)
|
||||
Dim storageFile = Await StorageFileHelper.WriteTextToLocalCacheFileAsync(myText, "appFilename.txt")
|
||||
|
||||
' Load some text from a file named appFilename.txt in the local cache folder
|
||||
Dim loadedText As String = Await StorageFileHelper.ReadTextFromLocalCacheFileAsync("appFilename.txt")
|
||||
|
||||
' Save some text to a file named appFilename.txt (in the local folder)
|
||||
storageFile = Await StorageFileHelper.WriteTextToLocalFileAsync(myText, "appFilename.txt")
|
||||
|
||||
' Load some text from a file named appFilename.txt in the local folder
|
||||
loadedText = Await StorageFileHelper.ReadTextFromLocalFileAsync("appFilename.txt")
|
||||
|
||||
' Check if a file exists in a specific folder
|
||||
Dim exists As Boolean = Await localFolder.FileExistsAsync("appFilename.txt")
|
||||
|
||||
' Check if a file exists in a specific folder or in one of its subfolders
|
||||
Dim exists As Boolean = Await localFolder.FileExistsAsync("appFilename.txt", True)
|
||||
|
||||
' Check if a file name is valid or not
|
||||
Dim isFileNameValid As Boolean = StorageFileHelper.IsFileNameValid("appFilename.txt")
|
||||
|
||||
' Check if a file path is valid or not
|
||||
Dim isFilePathValid As Boolean = StorageFileHelper.IsFilePathValid("folder/appFilename.txt")
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Streams Helper
|
|||
author: nmetulev
|
||||
description: There are several operations that apps need commonly to do against their APPX, or from the Internet that are not easy. This helper class wraps up some of the most common operations we need in multiple apps.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Streams
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Streams Helper
|
||||
|
@ -40,16 +43,29 @@ There are several operations that apps need commonly to do against their APPX, o
|
|||
// Get access to a text file that was included in solution as Content | do not copy local
|
||||
using (var stream = await StreamHelper.GetPackagedFileStreamAsync("Assets/Sub/test.txt"))
|
||||
{
|
||||
// Read the contents as ASCII text
|
||||
// Read the contents as ASCII text
|
||||
var readText = await stream.ReadTextAsync();
|
||||
}
|
||||
|
||||
// Get access to a HTTP ressource
|
||||
// Get access to a HTTP resource
|
||||
using (var stream = await StreamHelper.GetHttpStreamAsync(new Uri("http://dev.windows.com")))
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Get access to a text file that was included in solution as Content | do not copy local
|
||||
Using stream = Await StreamHelper.GetPackagedFileStreamAsync("Assets/Sub/test.txt")
|
||||
' Read the contents as ASCII text
|
||||
Dim readText = Await stream.ReadTextAsync()
|
||||
...
|
||||
End Using
|
||||
|
||||
' // Get access to a HTTP resource
|
||||
Using stream = Await StreamHelper.GetHttpStreamAsync(New Uri("http://dev.windows.com"))
|
||||
...
|
||||
End Using
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
@ -65,4 +81,3 @@ You can find more examples in our [unit tests](https://github.com/Microsoft/UWPC
|
|||
## API Source Code
|
||||
|
||||
* [Stream Helper source code](https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp/Helpers/StreamHelper.cs)
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Theme Listener
|
|||
author: williamabradley
|
||||
description: The Theme Listener allows you to determine the current Application Theme, and when it is changed via System Theme changes.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, theme listener, themeing, themes, system theme, helpers
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Theme Listener
|
||||
|
@ -21,6 +24,15 @@ private void Listener_ThemeChanged(ThemeListener sender)
|
|||
// Use theme dependent code.
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim listener = New ThemeListener()
|
||||
AddHandler listener.ThemeChanged, AddressOf Listener_ThemeChanged
|
||||
|
||||
Private Sub Listener_ThemeChanged(ByVal sender As ThemeListener)
|
||||
Dim theme = sender.CurrentTheme
|
||||
' Use theme dependent code.
|
||||
End Sub
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Markdown Parser
|
|||
author: williamabradley
|
||||
description: The Markdown Parser allows you to parse a Markdown String into a Markdown Document, and then Render it with a Markdown Renderer.
|
||||
keywords: uwp community toolkit, uwp toolkit, microsoft community toolkit, microsoft toolkit, markdown, markdown parsing, parser, markdown rendering
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Markdown Parser
|
||||
|
@ -13,8 +16,8 @@ The [MarkdownDocument](https://docs.microsoft.com/en-us/dotnet/api/microsoft.too
|
|||
|
||||
```csharp
|
||||
string md = "This is **Markdown**";
|
||||
MarkdownDocument Document = new MarkdownDocument();
|
||||
Document.Parse(md);
|
||||
MarkdownDocument document = new MarkdownDocument();
|
||||
document.Parse(md);
|
||||
|
||||
// Takes note of all of the Top Level Headers.
|
||||
foreach (var element in document.Blocks)
|
||||
|
@ -25,6 +28,18 @@ foreach (var element in document.Blocks)
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim md As String = "This is **Markdown**"
|
||||
Dim document As MarkdownDocument = New MarkdownDocument()
|
||||
document.Parse(md)
|
||||
|
||||
For Each element In document.Blocks
|
||||
If TypeOf element Is HeaderBlock Then
|
||||
Console.WriteLine($"Header: {element.ToString()}")
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: RSS Parser
|
|||
author: williamabradley
|
||||
description: The RSS Parser allows you to parse an RSS content String into RSS Schema.
|
||||
keywords: uwp community toolkit, uwp toolkit, microsoft community toolkit, microsoft toolkit, rss, rss parsing, parser
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# RSS Parser
|
||||
|
@ -15,7 +18,6 @@ The [RssParser](https://docs.microsoft.com/en-us/dotnet/api/microsoft.toolkit.pa
|
|||
public async void ParseRSS()
|
||||
{
|
||||
string feed = null;
|
||||
RSSFeed.Clear();
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
|
@ -39,6 +41,26 @@ public async void ParseRSS()
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Public Async Sub ParseRSS()
|
||||
Dim feed As String = Nothing
|
||||
Using client = New HttpClient()
|
||||
Try
|
||||
feed = Await client.GetStringAsync("https://visualstudiomagazine.com/rss-feeds/news.aspx")
|
||||
Catch
|
||||
End Try
|
||||
End Using
|
||||
|
||||
If feed IsNot Nothing Then
|
||||
Dim parser = New RssParser()
|
||||
Dim rss = parser.Parse(feed)
|
||||
For Each element In rss
|
||||
Console.WriteLine($"Title: {element.Title}")
|
||||
Console.WriteLine($"Summary: {element.Summary}")
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Bing Service
|
|||
author: nmetulev
|
||||
description: The Bing Service allows you to retrieve Bing results. Bing can return web and news results in your language, images, and videos for many countries around the world.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, bing
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Bing Service
|
||||
|
@ -33,6 +36,17 @@ var searchConfig = new BingSearchConfig
|
|||
|
||||
ListView.ItemsSource = await BingService.Instance.RequestAsync(searchConfig, 50);
|
||||
```
|
||||
```vb
|
||||
Imports using Microsoft.Toolkit.Uwp.Services.Bing
|
||||
|
||||
Dim searchConfig = New BingSearchConfig With {
|
||||
.Country = BingCountry.UnitedStates,
|
||||
.Language = BingLanguage.English,
|
||||
.Query = SearchText.Text,
|
||||
.QueryType = BingQueryType.Search
|
||||
}
|
||||
ListView.ItemsSource = Await BingService.Instance.RequestAsync(searchConfig, 50)
|
||||
```
|
||||
|
||||
## BingDataProvider Class
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Facebook Service
|
|||
author: nmetulev
|
||||
description: The Facebook Service allows you to retrieve or publish data to the Facebook graph. Examples of the types of objects you can work with are Posts, Tagged Objects, and the primary user feed.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Facebook Service
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Facebook Service
|
||||
|
@ -20,11 +23,18 @@ The Windows Store SID is a unique value per application generated, and it not ti
|
|||
System.Diagnostics.Debug.WriteLine("Windows Store SID = " + Microsoft.Toolkit.Uwp.Services.Facebook.FacebookService.Instance.WindowsStoreId);
|
||||
#endif
|
||||
```
|
||||
```vb
|
||||
' Put the following code in your mainform loaded event
|
||||
' Note that this will not work in the App.xaml.cs Loaded
|
||||
#If DEBUG Then
|
||||
System.Diagnostics.Debug.WriteLine("Windows Store SID = " & Microsoft.Toolkit.Uwp.Services.Facebook.FacebookService.Instance.WindowsStoreId)
|
||||
#End If
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
You may have to turn on the Output window in Visual Studio to see this debug writeline.
|
||||
|
||||
The above code will output something like this:
|
||||
The above code will output something like this:
|
||||
|
||||
```
|
||||
Windows Store SID = ms-app://s-1-15-2-12341451-1486691014-2395677208-123421631-1234998043-1234490472-123452499/
|
||||
|
@ -84,6 +94,36 @@ await FacebookService.Instance.GetUserAlbumsAsync();
|
|||
// Get current user's photos by album Id
|
||||
await FacebookService.Instance.GetUserPhotosByAlbumIdAsync(addedItem.Id);
|
||||
```
|
||||
```vb
|
||||
' Initialize service
|
||||
FacebookService.Instance.Initialize(AppIDText.Text)
|
||||
|
||||
' Login to Facebook
|
||||
If Not Await FacebookService.Instance.LoginAsync() Then
|
||||
Return
|
||||
End If
|
||||
|
||||
' Get user's feed
|
||||
ListView.ItemsSource = Await FacebookService.Instance.RequestAsync(FacebookDataConfig.MyFeed, 50)
|
||||
|
||||
' Get current user profile picture
|
||||
ProfileImage.DataContext = Await FacebookService.Instance.GetUserPictureInfoAsync()
|
||||
|
||||
' Post a message on your wall
|
||||
Await FacebookService.Instance.PostToFeedAsync(TitleText.Text, MessageText.Text, DescriptionText.Text, UrlText.Text)
|
||||
|
||||
' Post a message on your wall using Facebook Dialog
|
||||
Await FacebookService.Instance.PostToFeedWithDialogAsync(TitleText.Text, DescriptionText.Text, UrlText.Text)
|
||||
|
||||
' Post a message with a picture on your wall
|
||||
Await FacebookService.Instance.PostToFeedAsync(TitleText.Text, MessageText.Text, DescriptionText.Text, picture.Name, Stream)
|
||||
|
||||
' Get current user's photo albums
|
||||
Await FacebookService.Instance.GetUserAlbumsAsync()
|
||||
|
||||
' Get current user's photos by album Id
|
||||
Await FacebookService.Instance.GetUserPhotosByAlbumIdAsync(addedItem.Id)
|
||||
```
|
||||
|
||||
## FacebookAlbum Class
|
||||
|
||||
|
@ -228,7 +268,7 @@ Class for connecting to Facebook
|
|||
|
||||
| Methods | Return Type | Description |
|
||||
| -- | -- | -- |
|
||||
| Initialize(FacebookOAuthTokens, FacebookPermissions) | bool | Initialize underlying provider with relevent token information |
|
||||
| Initialize(FacebookOAuthTokens, FacebookPermissions) | bool | Initialize underlying provider with relevant token information |
|
||||
| LoginAsync() | Task<bool> | Login with set of required requiredPermissions |
|
||||
| LogoutAsync() | Task | Log out of the underlying service instance |
|
||||
| RequestAsync(FacebookDataConfig, int) | Task<List<FacebookPost>> | Request list data from service provider based upon a given config / query |
|
||||
|
|
|
@ -3,6 +3,9 @@ title: LinkedIn Service
|
|||
author: nmetulev
|
||||
description: The LinkedIn Service allows you to retrieve or publish data to the LinkedIn graph. Examples of the types of objects you can work with are User profile data and sharing Activity.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, LinkedIn Service
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# LinkedIn Service
|
||||
|
@ -13,7 +16,7 @@ The **LinkedIn Service** allows you to retrieve or publish data to the LinkedIn
|
|||
|
||||
1. Go to: https://www.linkedin.com/developer/apps.
|
||||
2. Select **Create Application**, to start integrating LinkedIn into your app.
|
||||
3. Complete all mandory fields signified by the red star. If you agree to the terms and conditions, hit **Submit**.
|
||||
3. Complete all mandatory fields signified by the red star. If you agree to the terms and conditions, hit **Submit**.
|
||||
4. Make a note of the **Client Id** and **Client Secret** for your app - you will need to supply these in your code.
|
||||
5. Take note of the **Default Application Permissions**. You can either set these in this portal or via code. These are the permissions your user will need to agree to for you to make calls on their behalf.
|
||||
6. Under **OAuth 2.0** you will need to enter a **Authorized Redirect URLs**. For UWP app development purposes this is arbitrary, but it will need to match what you have in your code (e.g. https://github.com/Microsoft/UWPCommunityToolkit).
|
||||
|
@ -37,8 +40,21 @@ await LinkedInService.Instance.GetUserProfileAsync();
|
|||
// Share message to LinkedIn (text should include a Url so LinkedIn can scrape preview information)
|
||||
await LinkedInService.Instance.ShareActivityAsync(ShareText.Text);
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
```vb
|
||||
' Initialize service - use overload if you need to supply additional permissions
|
||||
LinkedInService.Instance.Initialize(ClientId.Text, ClientSecret.Text, CallbackUri.Text)
|
||||
|
||||
' Login to LinkedIn
|
||||
If Not Await LinkedInService.Instance.LoginAsync() Then
|
||||
Return
|
||||
End If
|
||||
|
||||
' Get current user's profile details
|
||||
Await LinkedInService.Instance.GetUserProfileAsync()
|
||||
|
||||
' Share message to LinkedIn (text should include a Url so LinkedIn can scrape preview information)
|
||||
Await LinkedInService.Instance.ShareActivityAsync(ShareText.Text)
|
||||
```
|
||||
|
||||
[LinkedIn Service Sample Page Source](https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/LinkedIn%20Service). You can see this in action in [UWP Community Toolkit Sample App](https://www.microsoft.com/store/apps/9NBLGGH4TLCQ).
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: MicrosoftGraph Service
|
|||
author: nmetulev
|
||||
description: The MicrosoftGraph Service aim to easily logon to Office 365 Service in order to Retrieve User Information, Retrieve and Send emails, Retrieve User events
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, MicrosoftGraph Service
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# MicrosoftGraph Service
|
||||
|
@ -47,7 +50,7 @@ When you register your app in the [Azure Management Portal](http://manage.window
|
|||
* **Read user mail and Send mail as user** to retrieve/send messages.
|
||||
* **Read user calendars** to retrieve events.
|
||||
|
||||
**Note:** Once register copy and save the Client ID for futur use.
|
||||
**Note:** Once register copy and save the Client ID for future use.
|
||||
|
||||
|Setting|Value|
|
||||
|----------|:-------------:|
|
||||
|
@ -56,7 +59,6 @@ When you register your app in the [Azure Management Portal](http://manage.window
|
|||
|Resource to Add|Microsoft Graph|
|
||||
|Delegate Permissions |Sign in and read user profile, Read user mail and Send mail, Read user calendars|
|
||||
|
||||
|
||||
## Syntax
|
||||
|
||||
### Sign in with an Office 365 account
|
||||
|
@ -73,6 +75,17 @@ if (!await MicrosoftGraphService.Instance.LoginAsync())
|
|||
return;
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Initialize the service
|
||||
If Not MicrosoftGraphService.Instance.Initialize(ClientId.Text) Then
|
||||
Return
|
||||
End If
|
||||
|
||||
' Login via Azure Active Directory
|
||||
If Not Await MicrosoftGraphService.Instance.LoginAsync() Then
|
||||
Return
|
||||
End If
|
||||
```
|
||||
|
||||
### Get the connected user's info
|
||||
|
||||
|
@ -93,7 +106,7 @@ MicrosoftGraphUserFields[] selectedFields =
|
|||
};
|
||||
|
||||
var user =await MicrosoftGraphService.Instance.User.GetProfileAsync(selectedFields);
|
||||
UserPanel.DataContext = user;
|
||||
UserPanel.DataContext = user;
|
||||
|
||||
// Retrieve the user's photo
|
||||
using (IRandomAccessStream photoStream = await MicrosoftGraphService.Instance.User.GetPhotoAsync())
|
||||
|
@ -111,6 +124,36 @@ using (IRandomAccessStream photoStream = await MicrosoftGraphService.Instance.Us
|
|||
this.Photo.Source = photo;
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Retrieve user's info from Azure Active Directory
|
||||
Dim user = Await MicrosoftGraphService.Instance.User.GetProfileAsync()
|
||||
UserPanel.DataContext = user
|
||||
|
||||
' You can also select any fields you want in the response
|
||||
Dim selectedFields As MicrosoftGraphUserFields() = {
|
||||
MicrosoftGraphUserFields.Id,
|
||||
MicrosoftGraphUserFields.DisplayName,
|
||||
MicrosoftGraphUserFields.JobTitle,
|
||||
MicrosoftGraphUserFields.Mail,
|
||||
MicrosoftGraphUserFields.Department,
|
||||
MicrosoftGraphUserFields.PreferredLanguage
|
||||
}
|
||||
|
||||
Dim user = Await MicrosoftGraphService.Instance.User.GetProfileAsync(selectedFields)
|
||||
UserPanel.DataContext = user
|
||||
|
||||
' Retrieve the user's photo
|
||||
Using photoStream As IRandomAccessStream = Await MicrosoftGraphService.Instance.User.PhotosService.GetPhotoAsync()
|
||||
Dim photo As BitmapImage = New BitmapImage()
|
||||
If photoStream IsNot Nothing Then
|
||||
Await photo.SetSourceAsync(photoStream)
|
||||
Else
|
||||
photo.UriSource = New Uri("ms-appx:///SamplePages/MicrosoftGraph Service/user.png")
|
||||
End If
|
||||
|
||||
Me.Photo.Source = photo
|
||||
End Using
|
||||
```
|
||||
|
||||
### Retrieve/Send messages
|
||||
|
||||
|
@ -135,7 +178,7 @@ MessagesList.ItemsSource = messages;
|
|||
messages = await MicrosoftGraphService.Instance.User.Message.NextPageEmailsAsync();
|
||||
if (messages == null)
|
||||
{
|
||||
// no more messages
|
||||
// no more messages
|
||||
}
|
||||
|
||||
// Send a message
|
||||
|
@ -149,6 +192,37 @@ await MicrosoftGraphService.Instance.User.Message.SendEmailAsync(subject, conten
|
|||
string content = GetHtmlMessage();
|
||||
await MicrosoftGraphService.Instance.User.Message.SendEmailAsync(subject, content, BodyType.Html, toRecipients);
|
||||
```
|
||||
```vb
|
||||
' Get the top 10 messages
|
||||
messages = Await MicrosoftGraphService.Instance.User.Message.GetEmailsAsync(10)
|
||||
MessagesList.ItemsSource = messages
|
||||
|
||||
' You can also select any fields you want in the response
|
||||
Dim selectedFields As MicrosoftGraphMessageFields() = {
|
||||
MicrosoftGraphMessageFields.Id,
|
||||
MicrosoftGraphMessageFields.From,
|
||||
MicrosoftGraphMessageFields.Subject,
|
||||
MicrosoftGraphMessageFields.BodyPreview
|
||||
}
|
||||
messages = Await MicrosoftGraphService.Instance.User.Message.GetEmailsAsync(10, selectedFields)
|
||||
MessagesList.ItemsSource = messages
|
||||
|
||||
' Request the next 10 messages
|
||||
messages = Await MicrosoftGraphService.Instance.User.Message.NextPageEmailsAsync()
|
||||
If messages Is Nothing Then
|
||||
' no more messages
|
||||
End If
|
||||
|
||||
' Send a message
|
||||
Dim toRecipients As String() = {"user1@contoso.com", "user2@contoso.com"}
|
||||
Dim subject As String = "This is the subject of my message;"
|
||||
Dim content As String = "This is the content of my message"
|
||||
Await MicrosoftGraphService.Instance.User.Message.SendEmailAsync(subject, content, BodyType.Text, toRecipients)
|
||||
|
||||
' You can also send a message in html format
|
||||
Dim content As String = GetHtmlMessage()
|
||||
Await MicrosoftGraphService.Instance.User.Message.SendEmailAsync(subject, content, BodyType.Html, toRecipients)
|
||||
```
|
||||
|
||||
### Retrieve calendar events
|
||||
|
||||
|
@ -178,6 +252,29 @@ if (events == null)
|
|||
// no more events
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Get the top 10 events
|
||||
events = Await MicrosoftGraphService.Instance.User.[Event].GetEventsAsync(10)
|
||||
EventsList.ItemsSource = events
|
||||
|
||||
' You can also select any fields you want in the response
|
||||
Dim selectedFields As MicrosoftGraphEventFields() = {
|
||||
MicrosoftGraphEventFields.Id,
|
||||
MicrosoftGraphEventFields.Attendees,
|
||||
MicrosoftGraphEventFields.Start,
|
||||
MicrosoftGraphEventFields.HasAttachments,
|
||||
MicrosoftGraphEventFields.Subject,
|
||||
MicrosoftGraphEventFields.BodyPreview
|
||||
}
|
||||
events = Await MicrosoftGraphService.Instance.User.[Event].GetEventsAsync(10, selectedFields)
|
||||
EventsList.ItemsSource = events
|
||||
|
||||
' Request the next 10 events
|
||||
events = Await MicrosoftGraphService.Instance.User.[Event].NextPageEventsAsync()
|
||||
If events Is Nothing Then
|
||||
' no more events
|
||||
End If
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Microsoft Translator Service
|
|||
author: nmetulev
|
||||
description: The Microsoft Translator Service allows you to translate text to various supported languages.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, MicrosoftTranslator
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Microsoft Translator Service
|
||||
|
@ -11,7 +14,7 @@ The **Microsoft Translator Service** allows you to translate text to various sup
|
|||
|
||||
## Set up Microsoft Translator Service
|
||||
|
||||
[Signup for Microsot Translator Service](https://portal.azure.com/#create/Microsoft.CognitiveServices/apitype/TextTranslation) using your Microsoft Azure subscription account. There is a free trial option for that allows you to translate up to 2,000,000 characters per month.
|
||||
[Signup for Microsoft Translator Service](https://portal.azure.com/#create/Microsoft.CognitiveServices/apitype/TextTranslation) using your Microsoft Azure subscription account. There is a free trial option for that allows you to translate up to 2,000,000 characters per month.
|
||||
|
||||
## Example Syntax
|
||||
|
||||
|
@ -24,11 +27,25 @@ await TranslatorService.Instance.InitializeAsync("<translator service key");
|
|||
var languages = await TranslatorService.Instance.GetLanguageNamesAsync();
|
||||
|
||||
// Detects the language of a text.
|
||||
var language = await TranslatorService.Instance.DetectLanguageAsync();
|
||||
var language = await TranslatorService.Instance.DetectLanguageAsync("Hello everyone!");
|
||||
|
||||
// Translates the text to Italian.
|
||||
var translatedText = await TranslatorService.Instance.TranslateAsync("Hello everyone!", "it");
|
||||
```
|
||||
```vb
|
||||
' Imports Microsoft.Toolkit.Uwp.Services.MicrosoftTranslator
|
||||
|
||||
Await TranslatorService.Instance.InitializeAsync("<translator service key")
|
||||
|
||||
' Retrieves friendly names for the languages available for text translation.
|
||||
Dim languages = Await TranslatorService.Instance.GetLanguageNamesAsync()
|
||||
|
||||
' Detects the language of a text.
|
||||
Dim language = Await TranslatorService.Instance.DetectLanguageAsync("Hello everyone!")
|
||||
|
||||
' Translates the text to Italian.
|
||||
Dim translatedText = Await TranslatorService.Instance.TranslateAsync("Hello everyone!", "it")
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: OneDrive Service
|
|||
author: tgoodhew
|
||||
description: The OneDrive Service provides a simple way to access resources on either OneDrive or OneDrive for Business (Office 365).
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, OneDrive
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# OneDrive Service
|
||||
|
@ -67,6 +70,12 @@ Microsoft.Toolkit.Uwp.Services.OneDrive.OneDriveService.Instance.Initialize
|
|||
null,
|
||||
null);
|
||||
```
|
||||
```vb
|
||||
' Using the new converged authentication of the Microsoft Graph we can simply
|
||||
' call the Initialize method on the OneDriveService singleton when initializing
|
||||
' in UWP applications
|
||||
Microsoft.Toolkit.Uwp.Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, scopes, Nothing, Nothing)
|
||||
```
|
||||
|
||||
### Defining scopes
|
||||
More information on scopes can be found in this document [Authentication scopes](https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/msa-oauth#authentication-scopes)
|
||||
|
@ -78,23 +87,34 @@ if (scopes == null)
|
|||
scopes = new string[] { MicrosoftGraphScope.FilesReadAll };
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' If the user hasn't selected a scope then set it to FilesReadAll
|
||||
If scopes Is Nothing Then
|
||||
scopes = New String() {MicrosoftGraphScope.FilesReadAll}
|
||||
End If
|
||||
```
|
||||
|
||||
### Login
|
||||
```csharp
|
||||
|
||||
// Login
|
||||
if (!await OneDriveService.Instance.LoginAsync())
|
||||
{
|
||||
throw new Exception("Unable to sign in");
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Login
|
||||
If Not Await OneDriveService.Instance.LoginAsync() Then
|
||||
Throw New Exception("Unable to sign in")
|
||||
End If
|
||||
|
||||
### Retrieve the root of your OneDrive
|
||||
|
||||
```csharp
|
||||
|
||||
var folder = await OneDriveService.Instance.RootFolderForMeAsync();
|
||||
|
||||
```
|
||||
```vb
|
||||
Dim folder = Await OneDriveService.Instance.RootFolderForMeAsync()
|
||||
```
|
||||
|
||||
### Retrieving files
|
||||
|
@ -105,11 +125,20 @@ var folder = await OneDriveService.Instance.RootFolderForMeAsync();
|
|||
var OneDriveItems = await folder.GetItemsAsync();
|
||||
do
|
||||
{
|
||||
//Get the next page of items
|
||||
OneDriveItems = await folder.NextItemsAsync();
|
||||
// Get the next page of items
|
||||
OneDriveItems = await folder.NextItemsAsync();
|
||||
}
|
||||
while (OneDriveItems != null);
|
||||
```
|
||||
```vb
|
||||
' Once you have a reference to the Root Folder you can get a list of all items
|
||||
' List the Items from the current folder
|
||||
Dim OneDriveItems = Await folder.GetItemsAsync()
|
||||
Do
|
||||
' Get the next page of items
|
||||
OneDriveItems = Await folder.NextItemsAsync()
|
||||
Loop While OneDriveItems IsNot Nothing
|
||||
```
|
||||
|
||||
### Creating folders
|
||||
|
||||
|
@ -122,6 +151,14 @@ if (!string.IsNullOrEmpty(newFolderName))
|
|||
await folder.StorageFolderPlatformService.CreateFolderAsync(newFolderName, CreationCollisionOption.GenerateUniqueName);
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Then from there you can play with folders and files
|
||||
' Create Folder
|
||||
Dim newFolderName As String = Await OneDriveSampleHelpers.InputTextDialogAsync("New Folder Name")
|
||||
If Not String.IsNullOrEmpty(newFolderName) Then
|
||||
Await folder.StorageFolderPlatformService.CreateFolderAsync(newFolderName, CreationCollisionOption.GenerateUniqueName)
|
||||
End If
|
||||
```
|
||||
|
||||
### Navigating subfolders
|
||||
|
||||
|
@ -130,6 +167,11 @@ var currentFolder = await _graphCurrentFolder.GetFolderAsync(item.Name);
|
|||
OneDriveItemsList.ItemsSource = await currentFolder.GetItemsAsync(20);
|
||||
_graphCurrentFolder = currentFolder;
|
||||
```
|
||||
```vb
|
||||
Dim currentFolder = Await _graphCurrentFolder.GetFolderAsync(item.Name)
|
||||
OneDriveItemsList.ItemsSource = Await currentFolder.GetItemsAsync(20)
|
||||
_graphCurrentFolder = currentFolder
|
||||
```
|
||||
|
||||
### Moving, copying and renaming items
|
||||
|
||||
|
@ -144,6 +186,17 @@ await _onedriveStorageItem.CopyAsync(targetonedriveStorageFolder);
|
|||
// Rename Folder
|
||||
await _onedriveStorageItem.RenameAsync("NewLevel3");
|
||||
```
|
||||
```vb
|
||||
' OneDrive API treats all items the same whether file, folder, etc.
|
||||
' Move Folder
|
||||
Await _onedriveStorageItem.MoveAsync(targetonedriveStorageFolder)
|
||||
|
||||
' Copy Folder
|
||||
Await _onedriveStorageItem.CopyAsync(targetonedriveStorageFolder)
|
||||
|
||||
' Rename Folder
|
||||
Await _onedriveStorageItem.RenameAsync("NewLevel3")
|
||||
```
|
||||
|
||||
### Creating or uploading files less than 4MB
|
||||
|
||||
|
@ -158,6 +211,15 @@ if (selectedFile != null)
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Open the local file or create a local file if brand new
|
||||
Dim selectedFile = Await OpenLocalFileAsync()
|
||||
If selectedFile IsNot Nothing Then
|
||||
Using localStream = Await selectedFile.OpenReadAsync()
|
||||
Dim fileCreated = Await level3Folder.CreateFileAsync(selectedFile.Name, CreationCollisionOption.GenerateUniqueName, localStream)
|
||||
End Using
|
||||
End If
|
||||
```
|
||||
|
||||
### Creating or uploading files - that exceed 4MB
|
||||
|
||||
|
@ -175,6 +237,18 @@ if (selectedFile != null)
|
|||
}
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim selectedFile = Await OpenLocalFileAsync()
|
||||
If selectedFile IsNot Nothing Then
|
||||
Using localStream = Await selectedFile.OpenReadAsync()
|
||||
Shell.Current.DisplayWaitRing = True
|
||||
|
||||
' If the file exceed the Maximum size (ie 4MB)
|
||||
Dim largeFileCreated = Await folder.StorageFolderPlatformService.UploadFileAsync(selectedFile.Name, localStream, CreationCollisionOption.GenerateUniqueName, 320 * 1024)
|
||||
End Using
|
||||
End If
|
||||
```
|
||||
|
||||
### Downloading files
|
||||
|
||||
```csharp
|
||||
|
@ -187,6 +261,15 @@ using (var remoteStream = (await oneDriveFile.StorageFilePlatformService.OpenAsy
|
|||
await SaveToLocalFolder(remoteStream, oneDriveFile.Name);
|
||||
}
|
||||
```
|
||||
```vb
|
||||
' Download a file and save the content in a local file
|
||||
' Convert the storage item to a storage file
|
||||
Dim oneDriveFile = CType(item, Toolkit.Services.OneDrive.OneDriveStorageFile)
|
||||
Using remoteStream = TryCast((Await oneDriveFile.StorageFilePlatformService.OpenAsync()), IRandomAccessStream)
|
||||
' Use a helper method to open local filestream and write to it
|
||||
Await SaveToLocalFolder(remoteStream, oneDriveFile.Name)
|
||||
End Using
|
||||
```
|
||||
|
||||
### Retrieving file thumbnails
|
||||
|
||||
|
@ -198,6 +281,13 @@ using (var stream = (await file.StorageItemPlatformService.GetThumbnailAsync(Too
|
|||
await OneDriveSampleHelpers.DisplayThumbnail(stream, "thumbnail");
|
||||
}
|
||||
```
|
||||
```vb
|
||||
Dim file = CType((CType(e.OriginalSource, AppBarButton)).DataContext, Toolkit.Services.OneDrive.OneDriveStorageItem)
|
||||
Using stream = TryCast((Await file.StorageItemPlatformService.GetThumbnailAsync(Toolkit.Services.MicrosoftGraph.MicrosoftGraphEnums.ThumbnailSize.Large)), IRandomAccessStream)
|
||||
' Use a helper method to display the images on the xaml view
|
||||
Await OneDriveSampleHelpers.DisplayThumbnail(stream, "thumbnail")
|
||||
End Using
|
||||
```
|
||||
|
||||
## Sample Code
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ title: Twitter Service
|
|||
author: nmetulev
|
||||
description: The Twitter Service allows users to retrieve or publish data to Twitter.
|
||||
keywords: windows 10, uwp, uwp community toolkit, uwp toolkit, Twitter
|
||||
dev_langs:
|
||||
- csharp
|
||||
- vb
|
||||
---
|
||||
|
||||
# Twitter Service
|
||||
|
@ -99,6 +102,62 @@ await TwitterService.Instance.StartUserStreamAsync(async tweet =>
|
|||
// Stop receiving live tweets and events
|
||||
TwitterService.Instance.StopUserStream();
|
||||
```
|
||||
```vb
|
||||
' Initialize service
|
||||
TwitterService.Instance.Initialize(ConsumerKey.Text, ConsumerSecret.Text, CallbackUri.Text)
|
||||
|
||||
' Login to Twitter
|
||||
If Not Await TwitterService.Instance.LoginAsync() Then
|
||||
Return
|
||||
End If
|
||||
|
||||
' Get current user info
|
||||
Dim user = Await TwitterService.Instance.GetUserAsync()
|
||||
ProfileImage.DataContext = user
|
||||
|
||||
' Get user time line
|
||||
ListView.ItemsSource = Await TwitterService.Instance.GetUserTimeLineAsync(user.ScreenName, 50)
|
||||
|
||||
' Post a tweet
|
||||
Await TwitterService.Instance.TweetStatusAsync(TweetText.Text)
|
||||
Dim status = New TwitterStatus With {
|
||||
.Message = TweetText.Text,
|
||||
|
||||
' Optional parameters defined by the Twitter "update" API (they may all be null or false)
|
||||
|
||||
.DisplayCoordinates = True,
|
||||
.InReplyToStatusId = "@ValidAccount",
|
||||
.Latitude = validLatitude,
|
||||
.Longitude = validLongitude,
|
||||
.PlaceId = "df51dec6f4ee2b2c", ' As defined by Twitter
|
||||
.PossiblySensitive = True, ' As defined by Twitter (nudity, violence, or medical procedures)
|
||||
.TrimUser = True
|
||||
}
|
||||
Await TwitterService.Instance.TweetStatusAsync(status)
|
||||
|
||||
' Post a tweet with a picture
|
||||
Await TwitterService.Instance.TweetStatusAsync(TweetText.Text, stream)
|
||||
Await TwitterService.Instance.TweetStatusAsync(status, stream)
|
||||
|
||||
' Search for a specific tag
|
||||
ListView.ItemsSource = Await TwitterService.Instance.SearchAsync(TagText.Text, 50)
|
||||
|
||||
' Open a connection with the stream service in order to receive live tweets and events
|
||||
ListView.ItemsSource = _tweets
|
||||
Await TwitterService.Instance.StartUserStreamAsync(
|
||||
Async Sub(tweet)
|
||||
Await Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal,
|
||||
Sub()
|
||||
If tweet IsNot Nothing Then
|
||||
_tweets.Insert(0, tweet)
|
||||
End If
|
||||
End Sub)
|
||||
End Sub)
|
||||
|
||||
' Stop receiving live tweets and events
|
||||
TwitterService.Instance.StopUserStream()
|
||||
```
|
||||
|
||||
## Posting to timeline fails to appear
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче