Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
***************
Complex Properties - Break out a property into its own element syntax:
<Button Name="ClickMeButton"
HorizontalAlignment="Left"
Content="Click Me"
Margin="20,20,0,0"
VerticalAlignment="Top"
Click="ClickMeButton_Click"
Width="200"
Height="100"
>
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
Schemas define rules for XAML, for UWP, for designer support, etc.
<Grid Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
Auto - use the largest value of elements it contains to define the width / height
Elements put themselves into rows and columns using attached property syntax:
...
...
<Button Grid.Row="0" />
</Grid>
<StackPanel>
<TextBlock>Top</TextBlock>
<TextBlock>Bottom</TextBlock>
</StackPanel>
<SplitView Name="MySplitView"
CompactPaneLength="50"
IsPaneOpen="False"
DisplayMode="CompactInline"
OpenPaneLength="200" >
<SplitView.Pane>
</SplitView.Pane>
<SplitView.Content>
</SplitView.Content>
</SplitView>
Inline � Panel completely covers content. When expanded, panel pushes content.
CompactInline � Pane covers most of the Content. When expanded, panel pushes
content.
Overlay � Panel completely covers content. When expanded, panel covers content.
CompactOverlay � Panel covers most of the content. When expanded, panel covers
content.
You can load pages into a child frame or into the root frame:
Frame.Navigate(typeof(Page2), additionalParameter);
if (Frame.CanGoBack) {
Frame.GoBack();
}
if (Frame.CanGoForward) {
Frame.GoForward();
}
Create a global variable by declaring a static internal field in the App class
definition.
CheckBoxResultTextBlock.Text = MyCheckBox.IsChecked.ToString();
ToggleButtonResultTextBlock.Text = MyToggleButton.IsChecked.ToString();
<ToggleSwitch>
<ToggleSwitch.OffContent>
<TextBlock Text="I'm off right now." />
</ToggleSwitch.OffContent>
<ToggleSwitch.OnContent>
<TextBlock Text="I'm on!" />
</ToggleSwitch.OnContent>
</ToggleSwitch>
Use Character Map to find the code to display icons using Segoe MDL5 Assets.
Hamburger: 
Use ListBox and ListBoxItems for the navigation links inside of a SplitView.
<CalendarView SelectionMode="Multiple"
SelectedDatesChanged="MyCalendarView_SelectedDatesChanged" />
<Button Content="Flyout">
<Button.Flyout>
<Flyout x:Name="MyFlyout">
</Flyout>
</Button.Flyout>
</Button>
MyFlyout.Hide();
<Button Content="FlyoutMenu">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Text="Item 1" />
<MenuFlyoutItem Text="Item 2" />
<MenuFlyoutSeparator />
<MenuFlyoutSubItem Text="Item 3">
<MenuFlyoutItem Text="Item 4" />
<MenuFlyoutSubItem Text="Item 5">
<MenuFlyoutItem Text="Item 6" />
<MenuFlyoutItem Text="Item 7" />
</MenuFlyoutSubItem>
</MenuFlyoutSubItem>
<MenuFlyoutSeparator />
<ToggleMenuFlyoutItem Text="Item 8" />
</MenuFlyout>
</Button.Flyout>
</Button>
<!-- You can apply this to anything ... ex. Image: -->
<!-- https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn308516.aspx -->
<AutoSuggestBox Name="MyAutoSuggestBox"
QueryIcon="Find"
PlaceholderText="Search"
TextChanged="MyAutoSuggestBox_TextChanged" />
<ScrollViewer
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
</ScrollViewer>
You can put anything inside of it, however, don't put it inside of a StackPanel!
<Line X1="10"
X2="200"
Y1="10"
Y2="10"
Stroke="Black"
Fill="Black"
StrokeThickness="5"
StrokeEndLineCap="Triangle" />
<Polyline Canvas.Left="150"
Canvas.Top="0"
Stroke="Black"
StrokeThickness="5"
Fill="Red"
Points="50,25 0,100 100,100 50,25"
StrokeLineJoin="Round"
StrokeStartLineCap="Round"
StrokeEndLineCap="Round" />
<Rectangle />
<Ellipse />
Canvas.ZIndex="100"
The higher the ZIndex, the higher in the stack it appears (covering what is below
it).
https://dev.windows.com/en-us/design
<Page.Resources>
<SolidColorBrush x:Key="MyBrush" Color="Brown" />
<Style TargetType="Button" x:Key="MyButtonStyle">
<Setter Property="Background" Value="Blue" />
<Setter Property="FontFamily" Value="Arial Black" />
<Setter Property="FontSize" Value="36" />
</Style>
</Page.Resources>
<Application.Resources>
</Application.Resources>
<Page>
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
<ResourceDictionary Source="Dictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
http://bit.do/theme-resources
<App RequestedTheme="Light">
Many styles defined in generic.xaml used BasedOn attribute ... and you can too!
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="NarrowLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MyImage.Width" Value="200" />
<Setter Target="LayoutGrid.Background" Value="Blue" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MyImage.Width" Value="200" />
<Setter Target="LayoutGrid.Background" Value="Blue" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
http://bit.do/adaptive-ui
Use adaptive triggers to move StackPanels (filled with content) into different Grid
cells.
Example:
/DeviceFamily-Mobile
-- MainPage.xaml
/DeviceFamily-Desktop
-- MainPage.xaml
... or use a different file suffix for different device specific views:
MainPage.DeviceFamily-Mobile.xaml
MainPage.DeviceFamily-Desktop.xaml
http://bit.do/device-specific-views
<Page
...
xmlns:data="using:xBindDataExample.Models">
<Page.Resources>
<DataTemplate x:DataType="data:Book" x:Key="BookDataTemplate">
<StackPanel HorizontalAlignment="Center">
<Image Source="{x:Bind CoverImage}" />
<TextBlock Text="{x:Bind Title}" />
<TextBlock Text="{x:Bind Author}" />
</StackPanel>
</DataTemplate>
</Page.Resources>
...
<GridView ItemsSource="{x:Bind Books}"
IsItemClickEnabled="True"
ItemClick="GridView_ItemClick"
ItemTemplate="{StaticResource BookDataTemplate}">
</GridView>
...
Code Behind
------------
public MainPage()
{
this.InitializeComponent();
Books = BookManager.GetBooks();
}
2) Cut the Data Template out of the MainPage.xaml and copy it into the User
Control.
4) Modify the contents of the User Control changing x:Bind statements to utilize
object.property notation:
<UserControl>
<StackPanel>
<Image Source="{x:Bind Contact.AvatarPath}" />
<TextBlock Text="{x:Bind Contact.FirstName}" />
<TextBlock Text="{x:Bind Contact.LastName}" />
</StackPanel>
</UserControl>
public ContactTemplate()
{
this.InitializeComponent();
this.DataContextChanged += (s, e) => Bindings.Update();
}