Wpf ListView数据模板、控件模板和样式
仍在学习WPF…感谢您的帮助 有没有办法重构这个:Wpf ListView数据模板、控件模板和样式,wpf,xaml,styles,templating,staticresource,Wpf,Xaml,Styles,Templating,Staticresource,仍在学习WPF…感谢您的帮助 有没有办法重构这个: 变成这样: 只是想得到一个想法…我不需要精确的代码,伪代码应该足够了(我希望),提前谢谢 编辑:我问这个问题是因为我试图找到一种方法,用最少的静态资源引用来实现这一点。我意识到我可以提取模板和样式,但我希望有人能告诉我如何将其缩减为一个静态资源 是的,你想要(类似) ... 在这里放置更多属性 对于所有ListBox上需要的样式,请在App.xaml中使用Style TargetType=“{x:Type ListViewItem}>
变成这样:
只是想得到一个想法…我不需要精确的代码,伪代码应该足够了(我希望),提前谢谢
编辑:我问这个问题是因为我试图找到一种方法,用最少的静态资源引用来实现这一点。我意识到我可以提取模板和样式,但我希望有人能告诉我如何将其缩减为一个静态资源 是的,你想要(类似)
... 在这里放置更多属性
对于所有ListBox上需要的样式,请在App.xaml中使用Style TargetType=“{x:Type ListViewItem}>”
<ListBox Name="lbEvents"
VerticalAlignment="Stretch"
SelectionMode="Multiple"
Loaded="lbCenterEvents_Loaded"
HorizontalAlignment="Stretch"
BorderBrush="Transparent"
Background="Transparent"
SelectionChanged="lbCenterEvents_SelectionChanged"
ItemContainerStyle="{StaticResource KioskCheckboxListItemContainer}">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Grid.Column="0"
Margin="0,10,0,0"
Padding="5,30,5,10"
DockPanel.Dock="Top"
Style="{StaticResource KioskCheckBox}"
Background="{StaticResource brshSecondaryColor}"
FontSize="26"
HorizontalAlignment="Stretch"
IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
Content="{Binding DisplayDescriptionForKiosk}">
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="lbEvents" Style="{StaticResource MyFinalListBox}"
VerticalAlignment="Stretch"
SelectionMode="Multiple"
Loaded="lbCenterEvents_Loaded"
HorizontalAlignment="Stretch"
BorderBrush="Transparent"
Background="Transparent" />
<UserControl>
<UserControl.Resources>
<DataTemplate x:Key="MyItemTemplate" DataType="{x:Type MyDataType}">
<CheckBox Grid.Column="0"
Margin="0,10,0,0"
Padding="5,30,5,10"
DockPanel.Dock="Top"
Style="{StaticResource KioskCheckBox}"
Background="{StaticResource brshSecondaryColor}"
FontSize="26"
HorizontalAlignment="Stretch"
IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
Content="{Binding DisplayDescriptionForKiosk}">
</CheckBox>
</DataTemplate>
<Style x:Key="MyFinalListBox" TargetType="{x:Type ListBox}">
<Setter Property="SelectionMode" Value="Multiple" />
... put more properties here
</Style>
</UserControl.Resources>
</UserControl>
<ListBox Name="lbEvents"
ItemTemplate="{StaticResource MyItemTemplate}"
Style="{StaticResource MyFinalListBox}"
VerticalAlignment="Stretch"
Loaded="lbCenterEvents_Loaded"
HorizontalAlignment="Stretch"
BorderBrush="Transparent"
Background="Transparent" />