翻譯|使用教程|編輯:黃竹雯|2019-02-19 11:54:38.000|閱讀 538 次
概述:本教程主要介紹Microsoft旗下Visual Studio關于利用XAML工具創建用戶界面的相關知識
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Visual Studio是一款完備的工具和服務,可幫助您為Microsoft平臺和其他平臺創建各種各樣的應用程序。在本系列教程中將介紹如何為圖像編輯創建基本的用戶界面,有任何建議或提示請在下方評論區留言,我們會及時處理。
在第 1 部分中介紹了使用 XAML 設計器和 Visual Studio 提供的其他工具,本文將繼續介紹使用 XAML 編輯器直接處理 XAML 標記。
首先將根布局 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 類中的實際數據替換這些占位符。
將數據模板添加到網格視圖
xmlns:telerikInput="using:Telerik.UI.Xaml.Controls.Input"添加到以下最后一個xmlns條目后面
<Page x:Name="page" x:Class="PhotoLab.MainPage" xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="//schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:PhotoLab" xmlns:d="//schemas.microsoft.com/expression/blend/2008" xmlns:mc="//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 以及你剛剛創建的項模板。 但是可能不會看到分級控件,因為它的白星在白色背景中。
更多Visual Studio精彩教程敬請關注~
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn