2

バインディングをキャッチして複数のプロパティに複製できるようにするために、BindingExpressionタイプのSelectorにアタッチされたプロパティを定義しました。アタッチされたプロパティは、セレクターがXAMLで直接定義されている場合に正常に機能します。ただし、SelectorがDataTemplate内で定義されている場合、プロパティ変更ハンドラーは起動されません。

付属物件

public static readonly DependencyProperty EnumBindingProperty = DependencyProperty.RegisterAttached(
    "EnumBinding", typeof(BindingExpression), typeof(SelectorHelper),
    new PropertyMetadata(null, OnEnumBindingChanged));

使用法(有効)

<ComboBox AttachedProperties:SelectorHelper.EnumBinding="{Binding Phase}" />

使用法(無効)

<DataTemplate>
    <ComboBox AttachedProperties:SelectorHelper.EnumBinding="{Binding Phase}" />
</DataTemplate>

Snoopを使用してプロパティを評価すると、プロパティが自動的に更新されて機能し始めることがわかったため、タイミングの問題のようです。

ヘルプや説明をいただければ幸いです。:)

4

1 に答える 1

1

式が式として保存され、評価されていないため、バインディングの評価が可能な限り遅れているようです。添付プロパティタイプをに変更することで、評価を強制できますobject

public static readonly DependencyProperty EnumBindingProperty = DependencyProperty.RegisterAttached(
    "EnumBinding", typeof(object), typeof(SelectorHelper),
    new PropertyMetadata(null, OnEnumBindingChanged));

これにより、バインディングができるだけ早く評価されます。次に、プロパティが設定されたときにそのプロパティからBindingExpressionを抽出し、現在そこにある直接設定されたBindingExpression値の代わりにそれを使用できます。

BindingOperations.GetBindingExpression(dObj, EnumBindingProperty)
于 2011-03-21T18:18:46.683 に答える