카테고리 없음
WPF Button에 Command Binding Error code 40 이슈
디해가태구디
2023. 6. 9. 14:43
<DataTemplate> 안에서
Command를 Binding 하는 부분에서 계속 이런 이슈가 생겼는데
The problem that I have is getting my button to work with the binding. I'm not sure what to set the DataContext. I am getting this error with my binding:
System.Windows.Data Error: 40 : BindingExpression path error: 'ClickMeCommand' property not found on 'object' ''Person' (HashCode=13029119)'. BindingExpression:Path=ClickMeCommand; DataItem='Person' (HashCode=13029119); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
왜 안되는지 거의 하루? 반나절을 끙끙거리다가
스택오버플로우 형님께서 DataTemplate안에서 Command 를 Binding 할 때 접근이 안된다고
RelativeSource를 써서 해야한다고 알려주셨다.........
앞으로 사용할 때 주의하자 !!
<DataTemplate>
<Border Background="{Binding Path=Color}" BorderThickness="1" BorderBrush="Black" Margin="10,2,0,2" ToolTip="{Binding Path=SeriesID}">
<StackPanel Orientation="Horizontal">
<Button x:Name="btn_deleteItem" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=DataContext.btnClickCommand }" Padding="2"
>
<ContentControl >
<Image Source="minus-condition.png" />
</ContentControl>
</Button>
<CheckBox IsChecked="{Bindin