2015-08-10 4 views
2

Что я делаю неправильно, чтобы получить эту ошибку?привязка предка WPF

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

ответ

1

A RelativeSource связывание возвращает элемент пользовательского интерфейса. Необходимо указать, что свойство находится в объекте DataContext:

<Button Grid.Row="0" Content="Button" Command="{Binding DataContext.CloseInstanceCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CFDOpenPositionsView}}}" 
Смежные вопросы