你好,我的事件设置器有问题。
我的窗口:
<TreeView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="CrefoChartTreeViewItemStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<HierarchicalDataTemplate
DataType="{x:Type local:Node}"
ItemsSource="{Binding ChildNodes}">
</HierarchicalDataTemplate>
</ResourceDictionary>
</TreeView.Resources>
我的 CrefoChartTreeViewItemStyle.xaml
<ResourceDictionary 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:ed="http://schemas.microsoft.com/expression/2010/drawing"
mc:Ignorable="d"
>
<Style TargetType="TreeViewItem">
<Style.Resources>
<LinearGradientBrush x:Key="ButtonBrush" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="White" Offset="0.25"/>
<GradientStop Color="#FFA5DBE9" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="{DynamicResource ButtonBrush}" />
<EventSetter Event="Click" Handler="ButtonOnClick" />
</Style>
</Style.Resources>
编译时收到错误消息:
The event 'click' can not be specified on a Target tag in a Style. Instead, use "EventSetter".
我做错了什么?
有没有其他方法可以触发树视图中的这个按钮?所以我可以把代码放在后面?