在控件模板和為其提供支持的代碼之間有一個隱含約定。如果使用自定義控件模板替代控件的標準模板,就需要確保新模板能夠滿足控件的實現(xiàn)代碼的所有需要。
在簡單控件中,這個過程就比較容易,因為對模板幾乎沒有(或者完全沒有)什么真正的要求。對于復雜控件,問題就顯得有些微妙了,因為控件的外觀和實現(xiàn)不可能是完全相互獨立的。對于這種情況,控件需要對其可視化顯示做出一些假設,而不管曾經(jīng)被設計得多么好。
在前面已經(jīng)看到了控件模板的這種需求的兩個例子,占位元素(如ContentPresenter和ItemsPresenter)和模板綁定。為成功地創(chuàng)建控件模板,需要仔細查看相關控件的標準模板,并注意分析這些技術的用法,然后將它們應用到自己的模板中。
嵌套的模板
按鈕控件的模板可分解成幾個較簡單的部分。然而,許多模板并非如此簡單。在某些情況下,控件模板將包含每個自定義模板也需要的大量元素。而在有些情況下,改變控件的外觀涉及創(chuàng)建多個模板。
例如,假設計劃修改熟悉的ListBox控件。創(chuàng)建這個示例的第一部是為ListBox控件設計模板,并酌情添加自動應用模板的樣式。
<Style TargetType="{x:Type ListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border Name="Border" Background="{StaticResource ListBoxBackgroundBrush}" BorderBrush="{StaticResource StandardBorderBrush}" BorderThickness="1" CornerRadius="3">
<ScrollViewer Focusable="False">
<ItemsPresenter Margin="2"></ItemsPresenter>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
該樣式使用兩個畫刷繪制邊框和背景。實際模板是標準模板ListBox的簡化版本。在Border元素內(nèi)部是為列表提供滾動功能的 ScrollViewer 元素以及容納所有列表項的 ItemsPresenter 元素。
對于該模板,最值得注意之處是它未提供的功能——配置列表中各項的外觀。沒有改功能,被選擇的元素總是使用熟悉的藍色背景突出顯示。為改變這種行為,需要為ListBoxItem控件添加控件模板,ListBoxItem 控件時封裝列表中每個單獨元素內(nèi)容的內(nèi)容控件。
與ListBox模板一樣,可使用元素類型樣式應用ListBoxItem模板。下面的基本模板在一個不可見的邊框中封裝了每個項。因為ListBoxItem是內(nèi)容控件,所以需要使用ContentPresenter 元素在其內(nèi)部放置項的內(nèi)容。除這些基本內(nèi)容外,還有當鼠標移動到項上或單擊時做出響應的觸發(fā)器:
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Name="Border" BorderThickness="2" CornerRadius="3" Padding="1" SnapsToDevicePixels="True">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ListBoxItem.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" To="20" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ListBoxItem.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" BeginTime="0:0:0.5" Duration="0:0:0.2"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource HoverBorderBrush}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
<Setter TargetName="Border" Property="TextBlock.Foreground" Value="{StaticResource SelectedForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
總之,可以使用這兩個模板創(chuàng)建當鼠標移動到當前定位的項上時使用動畫放大項的列表框。因為每個ListBoxItem可具有自己的動畫,所以當用戶在列表框中上下移動鼠標時,將看到幾個項開始增大,然后再次收縮。需要注意,縮小動畫省略了From和To屬性,通過這種方式,縮小動畫總將文本從當前尺寸縮小到它原來的尺寸。
修改滾動條
列表框還有一個方面沒有改變:右邊的滾動條。它是ScrollViewer 元素的一部分,ScrollViewer元素是ListBox模板的一部分。盡管這里重新定義了ListBox模板,但沒有替換ScrollBar的ScrollViewer。
為自定義該細節(jié),可為ListBox控件創(chuàng)建一個新的ScrollViewer模板,然后可將 ScrollViewer模板指向自定義的ScrollBar模板。然而 ,還有更簡單的選擇。可創(chuàng)建一個改變所有ScrollBar控件模板的特性于元素類型的樣式。這樣就避免了創(chuàng)建ScrollViewer模板所需的額外工作。
當然,還需要考慮這種設計會對應用程序的其他部分造成什么影響。如果創(chuàng)建元素類型樣式ScrollBar,并將其添加到窗口的Resources集合中,對于窗口的所有控件,無論何時使用ScrollBar控件,都會具有新樣式的滾動條,這可能正是您所希望的效果。另一方面,如果希望只改變ListBox控件中的滾動條,就必須為ListBox控件本身的資源集合添加元素類型樣式 ScrollBar。最后,如果希望改變整個應用程序中所有滾動條的外觀,可將該樣式添加到 App.xaml文件的資源集合中。
ScrollBar控件出奇復雜,它實際上是一個由更小部分組成的集合。
滾動條的背景有Track類表示——實際上是一個具有陰影并且被拉伸沾滿整個滾動條長度的矩形。滾動條的末尾處是按鈕,通過這些按鈕可以向上或向下(或向左或向右)滾動一個步長。這些按鈕時RepeatButton類的實例,該類繼承自ButtonBase類。RepeatButton類和普通Button類之間的重要區(qū)別在于,如果在RepeatButton按鈕上保持鼠標為按下狀態(tài),就會反復觸發(fā)Click事件(對于滾動條這是非常方便的)。
在滾動條的中間是代表當前滾動內(nèi)容中當前位置的Thumb元素。并且最有趣的是,滑塊兩側的空白實際上由另外兩個RepeatButton 對象構成,它們是透明的。當單擊這兩個按鈕中的一個時,滾動條會滾動一整頁(一頁是滾動內(nèi)容所在的可見窗口中的內(nèi)容量)。通過單擊滑塊兩側的條形區(qū)域,可快速瀏覽滾動內(nèi)容,這一功能是大家所熟悉的。
下面是用于垂直滾動條的模板:
<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="18"/>
<RowDefinition Height="*"/>
<RowDefinition MaxHeight="18"/>
</Grid.RowDefinitions>
<RepeatButton Grid.Row="0" Height="18" Style="{StaticResource ScrollBarLineButtonStyle}" Command="ScrollBar.LineUpCommand" >
<Path Fill="{StaticResource GlyphBrush}" Data="M 0 4 L 8 4 L 4 0 Z"></Path>
</RepeatButton>
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="True" ViewportSize="0">
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumbStyle}"></Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.IncreaseRepeatButton>
</Track>
<RepeatButton Grid.Row="3" Height="18" Style="{StaticResource ScrollBarLineButtonStyle}" Command="ScrollBar.LineDownCommand">
<Path Fill="{StaticResource GlyphBrush}" Data="M 0 0 L 4 4 L 8 0 Z"></Path>
</RepeatButton>
</Grid>
</ControlTemplate>
一旦理解滾動條的多部分結構,上面的模板就非常直觀了。下面列出需要注意的幾個要點:
1、垂直滾動條由一個包含三行的網(wǎng)格構成。頂行和底行容納兩端的按鈕(并顯示為箭頭)。它們固定占用18個單位。中間部分容納Track元素,占用了剩余空間。
2、兩端的RepeatButton元素使用相同的樣式。唯一的區(qū)別是Content屬性,該屬性包含了一個用于繪制箭頭的Path對象,因為頂部具有上箭頭而底部的按鈕具有下箭頭。為簡明起見,這些箭頭使用微語言路徑。其他細節(jié)(如背景填充和箭頭周圍顯示的圓圈)是在控件模板中定義的。
3、兩個按鈕都鏈接到ScrollBar類的命令(LineUpCommand 和 LineDownCommand)。這正是其工作原理。只要提供鏈接到這個命令的按鈕即可,不必考慮按鈕的名稱是什么,也不必考慮其外觀像什么或使用哪個特定的類。
4、Track元素名為PART_Track。為使ScrollBar類能夠成功的關聯(lián)到它的代碼,必須使用這個名稱。如果查看ScrollBar類的默認模板(類似上面的模板,但更長一些),也會看到該元素。
5、Track.ViewportSize 屬性被設置為0,。這是該模板特有的實現(xiàn)細節(jié),可確保Thumb元素總有相同的尺寸(通常,滑塊根據(jù)內(nèi)容按比例地改變尺寸,因此如果滾動的內(nèi)容在窗口中基本上能夠顯示,這是滑塊會變得較長)。
6、Track元素封裝了兩個RepeatButton對象和Thumb元素。同樣,這些按鈕通過命令連接到適當?shù)墓δ堋?/p>
這里模板使用了鍵名,明確指定將它作為垂直滾動條,可確保它不能被自動應用,即使同時設置了TargetType屬性。這里使用這種方法的原因是,該模板只適用于垂直方向的滾動條。而且,如果ScrollBar.Orientation屬性設置為Vertical,元素類型樣式會使用觸發(fā)器自動應用控件模板:
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="18"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
</Trigger>
</Style.Triggers>
</Style>
盡管可以使用相同的基本部分很容易地創(chuàng)建水平滾動條,但這里沒有采取該步驟,從而保留了正常樣式的水平滾動條。
最后一項任務是填充格式化各個RepeatButton對象和Thumb元素的樣式。這些樣式比較簡單,但它們確實改變了滾動條的標準外觀。
<Style x:Key="ScrollBarLineButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Grid Margin="1">
<Ellipse Name="Border" StrokeThickness="1" Stroke="{StaticResource StandardBorderBrush}" Fill="{StaticResource StandardBrush}"></Ellipse>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Fill" Value="{StaticResource PressedBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Background="Transparent" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="1,0,1,0" />
<Setter Property="Background" Value="{StaticResource StandardBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource StandardBorderBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Ellipse Stroke="{StaticResource StandardBorderBrush}" Fill="{StaticResource StandardBrush}"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
與正常滾動條不同,在該模板中沒有為Track元素指定背景,所以保持原來的透明背景。這樣,列表框的輕微陰影漸變可透過滾動條顯示。
至此,ListBox自定義模板就完成了,這里定義的ScrollBar樣式會自動應用于ListBox模板中的ScrollViewer上。
代碼清單:
Resources/Brush.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="StandardBorderBrush" Color="#888" />
<SolidColorBrush x:Key="StandardBackgroundBrush" Color="#FFF" />
<SolidColorBrush x:Key="HoverBorderBrush" Color="#DDD" />
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Gray" />
<SolidColorBrush x:Key="SelectedForegroundBrush" Color="White" />
<LinearGradientBrush x:Key="ListBoxBackgroundBrush" StartPoint="0,0" EndPoint="1,0.001">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="White" Offset="0.6" />
<GradientStop Color="#DDDDDD" Offset="1.2"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="StandardBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<SolidColorBrush x:Key="GlyphBrush" Color="#444" />
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#BBB" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="0.1"/>
<GradientStop Color="#EEE" Offset="0.9"/>
<GradientStop Color="#FFF" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</ResourceDictionary>
Resources/ScrollBar.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brush.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="ScrollBarLineButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Grid Margin="1">
<Ellipse Name="Border" StrokeThickness="1" Stroke="{StaticResource StandardBorderBrush}" Fill="{StaticResource StandardBrush}"></Ellipse>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Fill" Value="{StaticResource PressedBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Background="Transparent" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="1,0,1,0" />
<Setter Property="Background" Value="{StaticResource StandardBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource StandardBorderBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Ellipse Stroke="{StaticResource StandardBorderBrush}" Fill="{StaticResource StandardBrush}"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="18"/>
<RowDefinition Height="*"/>
<RowDefinition MaxHeight="18"/>
</Grid.RowDefinitions>
<RepeatButton Grid.Row="0" Height="18" Style="{StaticResource ScrollBarLineButtonStyle}" Command="ScrollBar.LineUpCommand" >
<Path Fill="{StaticResource GlyphBrush}" Data="M 0 4 L 8 4 L 4 0 Z"></Path>
</RepeatButton>
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="True" ViewportSize="0">
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumbStyle}"></Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.IncreaseRepeatButton>
</Track>
<RepeatButton Grid.Row="3" Height="18" Style="{StaticResource ScrollBarLineButtonStyle}" Command="ScrollBar.LineDownCommand">
<Path Fill="{StaticResource GlyphBrush}" Data="M 0 0 L 4 4 L 8 0 Z"></Path>
</RepeatButton>
</Grid>
</ControlTemplate>
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="18"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
Resources/ListBox.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brush.xaml"></ResourceDictionary>
<ResourceDictionary Source="ScrollBar.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border Name="Border" Background="{StaticResource ListBoxBackgroundBrush}" BorderBrush="{StaticResource StandardBorderBrush}" BorderThickness="1" CornerRadius="3">
<ScrollViewer Focusable="False">
<ItemsPresenter Margin="2"></ItemsPresenter>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Name="Border" BorderThickness="2" CornerRadius="3" Padding="1" SnapsToDevicePixels="True">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ListBoxItem.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" To="20" Duration="0:0:1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="ListBoxItem.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" BeginTime="0:0:0.5" Duration="0:0:0.2"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource HoverBorderBrush}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
<Setter TargetName="Border" Property="TextBlock.Foreground" Value="{StaticResource SelectedForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
MainWindow.xaml文章來源:http://www.zghlxwxcb.cn/news/detail-731856.html
<Window x:Class="TestControlTemplate2.MainWindow"
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"
xmlns:local="clr-namespace:TestControlTemplate2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ListBox.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ListBox Margin="5" ScrollViewer.CanContentScroll="False">
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
<ListBoxItem>Four</ListBoxItem>
<ListBoxItem>Five</ListBoxItem>
<ListBoxItem>Six</ListBoxItem>
<ListBoxItem>Seven</ListBoxItem>
<ListBoxItem>EightEight</ListBoxItem>
<ListBoxItem>NineNineNine</ListBoxItem>
<ListBoxItem>TenTenTenTen</ListBoxItem>
<ListBoxItem>ElevenElevenElevenEleven</ListBoxItem>
<ListBoxItem>TwelveTwelveTwelveTwelveTwelve</ListBoxItem>
</ListBox>
</Grid>
</Window>
MainWindow.xaml.cs文章來源地址http://www.zghlxwxcb.cn/news/detail-731856.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestControlTemplate2;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
到了這里,關于WPF控件模板2的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!