我可以使ListView的以下样式作为用户控件(或窗口)工作:
<ListView.ItemContainerStyle>
<Style TargetType="Control">
<Style.Resources>
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
x:Shared="False"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlTextBrushKey}"
x:Shared="False"
Color="{DynamicResource {x:Static SystemColors.HighlightTextColorKey}}" />
</Style.Resources>
<EventSetter
Event="MouseLeftButtonUp"
Handler="ListView_Content_MouseLeftButtonUpEvent" />
</Style>
</ListView.ItemContainerStyle>如何在自定义控件中获得相同的结果?我需要"x:Shared“,以便当系统颜色改变时重新计算颜色。我需要EventSetter来做一些特殊的处理。但是,在Generic.xaml中都不支持这两种方法。在自定义控件中获取这些功能的正确方法是什么?
谢谢。
发布于 2012-07-31 05:11:04
我能够在Generic.xaml中使用Style.Resources,所以我不知道那里可能出了什么问题。
若要附加事件处理程序,请重写自定义控件的OnApplyTemplate并在代码中添加事件处理程序。
https://stackoverflow.com/questions/11729335
复制相似问题