2012-07-30 41 views
1

我可以做以下样式的ListView的工作,作为一个用户控件(或窗口):自定义控件风格:共享和EventSetter

<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中都不受支持。在自定义控件中获取这些功能的正确方法是什么?

谢谢。

回答

0

我能够使用Generic.xaml中的Style.Resources,所以我不明白那里可能有什么问题。

要附加事件处理程序,请覆盖自定义控件的OnApplyTemplate并在代码中添加事件处理程序。