1

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

谢谢你。

4

1 回答 1

0

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

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

于 2012-07-30T21:11:04.257 回答