對于初始版本,一切都很好:
<ContentPresenter>
<ContentPresenter.Content>
<MultiBinding Converter="{StaticResource WhateverConverter}">
<Binding/>
<Binding Path="DummyObject"/>
</MultiBinding>
</ContentPresenter.Content>
</ContentPresenter>
但我系結后Content的ContentPresenter到Tag的元素,它不作業,我不知道為什么會這樣。
<ContentPresenter Content="{Binding Path=Tag, RelativeSource={RelativeSource Self}}">
<ContentPresenter.Tag>
<MultiBinding Converter="{StaticResource WhateverConverter}">
<Binding/>
<Binding Path="DummyObject"/>
</MultiBinding>
</ContentPresenter.Tag>
</ContentPresenter>
PS:我使用NotifyTask來實作一個異步值轉換器,所以我需要執行一個所謂的兩步轉換。
uj5u.com熱心網友回復:
您必須知道DataContextaContentPresenter的Content值。因此,Binding第二個示例中的 行為與您預期的不同(不同Binding.Source)。
在您的第二個示例中,您將ContentPresenter.Contentto設定為系結到它自己的ContentPresenter.Tag屬性。這使得ContentPresenter.Tag對DataContext的ContentPresenter。現在屬性Binding上的setTag具有ContentPresenter.TagasBinding源 ( DataContext) 而不是父元素的DataContext。
如果你想做你正在做的事情,你應該ContentPresenter用一個ContentControl. ContentControl不會改變它的DataContext。
的ContentPresenter主要設計內的要使用ControlTemplate的一個ContentControl,其中,所述ContentPresenterautomatucally結合到父ContentControl.Content屬性。persenter只對內容(呈現它)感興趣,而不DataContext對父控制元件的內容感興趣。這就是為什么ContentPresenter對它的DataContext. 也許這個名字ContentPresenter現在更有意義了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/376956.html
