[英]Binding to a nested property in template
我想為異步方法創建一個帶加載指示符的按鈕,如下所示:
我創建了一個實現ICommand
和INotifyPropertyChanged
的AsyncCommand
(更多細節見MSDN雜志2014年4月)。
我的AsyncCommand
具有Execution
屬性,它具有IsNotCompleated
屬性。 我想設置Visibility
裝載機的財產indincator使用IsNotCompleted
財產。
我創建UserControl繼承Button
並為此設置樣式。 我嘗試將可見性綁定到Button的Command
依賴項屬性。
ControlTemplate
的一部分帶有“加載指示器”(我使用內容,而不是可見性,僅作為示例)
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.Column="1"
Content="{Binding Command.Execution.IsNotCompleted}"/>
沒有任何反應。 如果我使用TemplateBinding
而不是Binding
我將得到編譯錯誤:
Command.Execution
這樣做的正確方法是什么?
解決方案是使用RelativeSource.TemplatedParent
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.Column="1"
Content="{Binding Command.Execution.IsNotCompleted, RelativeSource={RelativeSource TemplatedParent}}"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.