Visual Studio是一款完备的工具和服务,可帮助您为Microsoft平台和其余平台建立各类各样的应用程序。在本系列教程中将介绍如何为图像编辑建立基本的用户界面,有任何建议或提示请在下方评论区留言,咱们会及时处理。
express
在第 1 部分中介绍了使用 XAML 设计器和 Visual Studio 提供的其余工具,本文将继续介绍使用 XAML 编辑器直接处理 XAML 标记。bash
首先将根布局 Grid 替换为 RelativePanel。 利用 RelativePanel,可更加轻松地相对于面板或其余部分 UI 从新排列 UI 块,而后添加 GridView 控件以显示你的数据。编辑器
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="TitleTextBlock"
Text="Collection"
Margin="24,0,0,24"
Style="{StaticResource TitleTextBlockStyle}"/>
</Grid>复制代码
以后<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="TitleTextBlock"
Text="Collection"
Margin="24,0,0,24"
Style="{StaticResource TitleTextBlockStyle}"/>
</RelativePanel>复制代码
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="TitleTextBlock"
Text="Collection"
Margin="24,0,0,24"
Style="{StaticResource TitleTextBlockStyle}"/>
</RelativePanel>复制代码
添加到如下 TextBlock 以后<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="TitleTextBlock"
Text="Collection"
Margin="24,0,0,24"
Style="{StaticResource TitleTextBlockStyle}"/>
<!-- Add the GridView here. -->
</RelativePanel>复制代码
ImageGridView.ItemsSource = Images;复制代码
这会将 GridView 的 ItemsSource 属性设置为应用的 Images 集合,并为 GridView 提供要显示的内容。这是运行应用并确保一切正常工做的好地方。 它应该以下所示。工具
这部分将建立 DataTemplate,以告诉 GridView 如何显示你的数据,目前将仅添加占位符以帮助建立所需的布局。 在 XAML 数据绑定教程中,你将用 ImageFileInfo 类中的实际数据替换这些占位符。布局
将数据模板添加到网格视图ui
xmlns:telerikInput="using:Telerik.UI.Xaml.Controls.Input"复制代码
添加到如下最后一个xmlns条目后面<Page x:Name="page"
x:Class="PhotoLab.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PhotoLab"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerikInput="using:Telerik.UI.Xaml.Controls.Input"
mc:Ignorable="d"
NavigationCacheMode="Enabled">复制代码
<Page.Resources>
<DataTemplate x:Key="ImageGridView_DefaultItemTemplate">
<Grid/>
</DataTemplate>
</Page.Resources>复制代码
<GridView x:Name="ImageGridView"
Margin="0,0,0,8"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.Below="TitleTextBlock"
ItemTemplate="{StaticResource ImageGridView_DefaultItemTemplate}"/>复制代码
<Grid/>复制代码
以后<Grid Height="300"
Width="300"
Margin="8">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>复制代码
<Grid Height="300"
Width="300"
Margin="8">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image x:Name="ItemImage"
Source="Assets/StoreLogo.png"
Stretch="Uniform" />
<StackPanel Orientation="Vertical"
Grid.Row="1">
<TextBlock Text="ImageTitle"
HorizontalAlignment="Center"
Style="{StaticResource SubtitleTextBlockStyle}" />
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<TextBlock Text="ImageFileType"
HorizontalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}" />
<TextBlock Text="ImageDimensions"
HorizontalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Margin="8,0,0,0" />
</StackPanel>
<telerikInput:RadRating Value="3"
IsReadOnly="True">
<telerikInput:RadRating.FilledIconContentTemplate>
<DataTemplate>
<SymbolIcon Symbol="SolidStar"
Foreground="White" />
</DataTemplate>
</telerikInput:RadRating.FilledIconContentTemplate>
<telerikInput:RadRating.EmptyIconContentTemplate>
<DataTemplate>
<SymbolIcon Symbol="OutlineStar"
Foreground="White" />
</DataTemplate>
</telerikInput:RadRating.EmptyIconContentTemplate>
</telerikInput:RadRating>
</StackPanel>
</Grid>复制代码
如今,运行应用以查看 GridView 以及你刚刚建立的项模板。 可是可能不会看到分级控件,由于它的白星在白色背景中。spa