C1TileView 提供了數據交互瀏覽的功能。允許我們設置最大化和最小化瀏覽模板,我們可以通過最小化模板快速定位詳細瀏覽選項。
下面我們分步分享實現方法:
1.添加 C1TileView 到窗體,并且添加 8 個 C1TileViewItem。
wpf canvas 繪圖?2.添加 Image 地址作為 C1TileViewItem 顯示內容,并且設置 Header 屬性為圖片名。
<c1:C1TileViewItem Header="Jellyfish.jpg"
Content="Images/Jellyfish.jpg" />
設置最小化位置:
<c1:C1TileView Name="c1TileView1"
MinimizedItemsPosition="Bottom" UpdateSourceCollection="False">
wpf webview2?3.添加資源模板,添加最大化和最小化模板:
<UserControl.Resources>
??? <DataTemplate x:Key="template">
??????? <Grid>
??????????? <Image Source="{Binding}" />
??????? </Grid>
??? </DataTemplate>
??? <DataTemplate x:Key="mintemplate">
??????? <Grid Width="100" Height="75">
??????????? <Image Source="{Binding}" />
??????? </Grid>
??? </DataTemplate>
??? <Style TargetType="c1:C1TileViewItem">
??????? <Setter Property="Padding" Value="0" />
??????? <Setter Property="ContentTemplateMinimized" Value="{StaticResource mintemplate}" />
??????? <Setter Property="ContentTemplateMaximized" Value="{StaticResource template}" />
??????? <Setter Property="ContentTemplate" Value="{StaticResource template}" />
??? </Style>
</UserControl.Resources>
使用以上模板既可以完成圖片瀏覽庫的功能:
winform怎么添加圖片?詳細代碼:
<UserControl x:Class="TileViewPhotos.MainPage"
??? xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
??? xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
??? xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
??? xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
??? mc:Ignorable="d"
??? d:DesignHeight="300" d:DesignWidth="400" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">
??? <UserControl.Resources>
??????? <DataTemplate x:Key="template">
??????????? <Grid>
??????????????? <Image Source="{Binding}" />
??????????? </Grid>
??????? </DataTemplate>
??????? <DataTemplate x:Key="mintemplate">
??????????? <Grid Width="100" Height="75">
??????????????? <Image Source="{Binding}" />
??????????? </Grid>
??????? </DataTemplate>
??????? <Style TargetType="c1:C1TileViewItem">
??????????? <Setter Property="Padding" Value="0" />
??????????? <Setter Property="ContentTemplateMinimized" Value="{StaticResource mintemplate}" />
??????????? <Setter Property="ContentTemplateMaximized" Value="{StaticResource template}" />
??????????? <Setter Property="ContentTemplate" Value="{StaticResource template}" />
??????? </Style>
??? </UserControl.Resources>
??? <Grid x:Name="LayoutRoot" Background="White">
??????? <c1:C1TileView Name="c1TileView1" MinimizedItemsPosition="Bottom" UpdateSourceCollection="False">
??????????? <c1:C1TileViewItem Header="Chrysanthemum.jpg" Content="Images/Chrysanthemum.jpg" />
??????????? <c1:C1TileViewItem Header="Desert.jpg" Content="Images/Desert.jpg" />
??????????? <c1:C1TileViewItem Header="Hydrangeas.jpg" Content="Images/Hydrangeas.jpg" />
??????????? <c1:C1TileViewItem Header="Jellyfish.jpg" Content="Images/Jellyfish.jpg" />
??????????? <c1:C1TileViewItem Header="Koala.jpg" Content="Images/Koala.jpg" />
??????????? <c1:C1TileViewItem Header="Lighthouse.jpg" Content="Images/Lighthouse.jpg" />
??????????? <c1:C1TileViewItem Header="Penguins.jpg" Content="Images/Penguins.jpg" />
??????????? <c1:C1TileViewItem Header="Tulips.jpg" Content="Images/Tulips.jpg" />??????
??????? </c1:C1TileView>
??? </Grid>
</UserControl>
?
更多關于 Studio for WPF 控件及特性,請參考:
?
http://www.gcpowertools.com.cn/products/componentone_studio_wpf.htm