私はバインディングをユーザーコントロールの子オブジェクトで処理しようとしています。 XAMLは次のようになります。usercontrolの子依存オブジェクトのバインドが機能していない
<MyGrid>
<MyColumn ExtendedColumnData="{Binding ColumnToolTipDescriptions}"/>
</MyGrid>
ここでクラスが定義されている方法です。私は入れて試したように私は、バインディングでもデータを取得しようとされていない伝えることができるものから、
[ContentProperty("Columns")]
public class MyGrid : UserControl
{
private MyColumnCollection _columns;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("Data")]
public MyColumnCollection Columns
{
get
{
if (_columns == null)
_columns = new MyColumnCollection();
return _columns;
}
}
}
public class MyColumnCollection : ObservableCollection<MyGridColumn>
{
}
public class MyGridColumn : DependencyObject
{
public object ExtendedColumnData
{
get { return (object)GetValue(ExtendedColumnDataProperty); }
set { SetValue(ExtendedColumnDataProperty, value); }
}
public static readonly DependencyProperty ExtendedColumnDataProperty =
DependencyProperty.Register("ExtendedColumnData", typeof(object), typeof(MyGridColumn), new UIPropertyMetadata(null));
}
バインディングに対するコンバータ、Convertメソッドのブレークポイントは決してヒットしません。
MVVMパターンを使用しているため、ウィンドウのDataContext
プロパティがビューモデルに設定されています。
私はここにいくつかの他の質問を読んで、そのように結合の様々な置換しようとしました:
<MyColumn ExtendedColumnData="{Binding DataContext.ColumnToolTipDescriptions, ElementName=MyViewName}" />
<MyColumn ExtendedColumnData="{Binding DataContext.ColumnToolTipDescriptions, RelativeSource={RelativeSource AncestorType={x:Type local:MyView}}" />
しかし、まだ運、結合が発火しませんが!迷惑な事は、これは(私がグリッドにプロパティを追加した場合)、正常に動作するよう、次のとおりです。
<MyGrid ExtendedColumnData="{Binding ColumnToolTipDescriptions}">
<MyColumn />
</MyGrid>
私はありませんので、私は、私は何かが欠けてると確信しているWPFで経験していますか?
私はFreezableCollectionに変更しましたが、まだ動作していないようです。私は手動でDataContextを設定する必要はありませんか? –
ああ、MyGridColumnを忘れてしまった。また、そのクラスの基本クラスをFreezableに変更する必要がある。また、MyControlを含むUserControlまたはウィンドウに設定する必要があるDataContext。 ColumnToolTipDescriptionsプロパティを持つオブジェクトでなければなりません。 –