1
안녕하세요, 저는 Eventsetter에 문제가 있습니다.WPF Treeview Style EventSetter 작동하지 않습니다.
The event 'click' can not be specified on a Target tag in a Style. Instead, use "EventSetter".
내가 무슨 일을합니까 :
내 창 : 내가 컴파일 할 때
<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>
나는 오류 메시지가?
treeview 트리거에서이 단추를 가져 오는 다른 방법이 있습니까? 그래서 난 뒤에 코드를 넣을 수 있습니까?
동의하지 않음 - 리소스 사전 xamls *는 코드 숨김 파일을 가질 수 있습니다. 당신은 [이 질문에] 그것에 대해 읽을 수 있습니다 (http://stackoverflow.com/questions/92100/is-it-possible-to-set-code-behind-a-resource-dictionary-in-wpf-for- 이벤트 - handlin) 및 [이 질문에] (http://stackoverflow.com/questions/7045718/wpf-events-in-resourceced-for-a-controltemplate) (그리고 아마도 더). –
@ O.R.Mapper 당신이 옳다면, 그렇게까지 가면 가능합니다. 그러나 나는 그것이 보통의 경우가 아니라고 말할 것이다. – dowhilefor