gpt4 book ai didi

c# - WPF 祖先绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-03 13:02:35 26 4
gpt4 key购买 nike

出现此错误我做错了什么?

 xmlns:local="clr-namespace:TestSome.Views"

<Button Grid.Row="0" Content="Button" Command="{Binding CloseInstanceCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CFDOpenPositionsView}}}"
HorizontalAlignment="Left" Height="29.709" Margin="359.292,0,0,0" Style="{DynamicResource ButtonStyle4}" VerticalAlignment="Top" Width="66.728" Background="#FFDDDDDD" Visibility="Visible"/>

System.Windows.Data Error: 40 : BindingExpression path error: 'CloseInstanceCommand' property not found on 'object' ''CFDOpenPositionsView' (Name='')'. BindingExpression:
Path=CloseInstanceCommand; DataItem='CFDOpenPositionsView' (Name=''); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')

CFDOpenPositionView 类具有 CloseInstanceCommand 属性...

enter image description here

最佳答案

RelativeSource 绑定(bind)将返回一个 UI 元素。您需要指定该属性位于 DataContext 对象上:

<Button Grid.Row="0" Content="Button" Command="{Binding DataContext.CloseInstanceCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CFDOpenPositionsView}}}" 

关于c# - WPF 祖先绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31921164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com