2017-06-20 1 views
-2

私は、FindAncestorとAncestor TypeをDataGridとしてX:Typeとして設定し、そのパスにClickCommandを設定しました。私の質問は、FindAncestorとAncestorTypeをボタンコマンドの実際の振る舞いに設定する理由です。 Ancesstorをボタンで設定する方法とその目的は何ですか?

おかげ

+0

_IをしてモードFindAncestor_ ... _whyを設定してFindAncestor_を設定します。あなたはそれを設定しますが、その理由はわかりません。 – Maxim

+0

ようこそ!良い質問を書く際には、次のリンクを確認して、それに応じて編集してください: https://stackoverflow.com/help/how-to-ask – garfbradaz

答えて

0
FindAncestor and `AncestorType` 

は、何らかの理由で、あなたがあなたのコントロールとウィンドウのDataContextのアクセスができない場合は特に使用されています。

例としてこれを持っ:

<DataTemplate DataType="DataGridColumnHeader" > 
     <ComboBox ItemContainerStyle="{StaticResource SingleSelectionComboBoxItem}" DisplayMemberPath="Oggetto" Width="100" Height="20" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}},Path=DataContext.Selezione, UpdateSourceTrigger=LostFocus}" SelectionChanged="SingleSelectionComboBox_SelectionChanged"/> 
</DataTemplate> 

DataGridHeaderは、データグリッドのデータコンテキストを継承していないので、私は祖先からのDataContextを取ることsintaxtを使用していたとitemsourceを設定

関連する問題