[英]Binding to a nested property in template
I want to create a button with loading indicator for async methods, like this: 我想为异步方法创建一个带加载指示符的按钮,如下所示:
I create an AsyncCommand
implementing ICommand
and INotifyPropertyChanged
(more details in MSDN Magazine April, 2014). 我创建了一个实现ICommand
和INotifyPropertyChanged
的AsyncCommand
(更多细节见MSDN杂志2014年4月)。
My AsyncCommand
has Execution
property and it has IsNotCompleated
property. 我的AsyncCommand
具有Execution
属性,它具有IsNotCompleated
属性。 I want to set Visibility
property of loader indincator using IsNotCompleted
property. 我想设置Visibility
装载机的财产indincator使用IsNotCompleted
财产。
I create UserControl inherits the Button
and set style for this. 我创建UserControl继承Button
并为此设置样式。 I try to bind visibility to Button's Command
dependency property. 我尝试将可见性绑定到Button的Command
依赖项属性。
There the part of ControlTemplate
with "Loading indicator" (I use content, not Visibility, just for example) ControlTemplate
的一部分带有“加载指示器”(我使用内容,而不是可见性,仅作为示例)
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.Column="1"
Content="{Binding Command.Execution.IsNotCompleted}"/>
And nothing happens. 没有任何反应。 If i use TemplateBinding
instead of Binding
I'll get compile errors: 如果我使用TemplateBinding
而不是Binding
我将得到编译错误:
Command.Execution
无法找到类型Command.Execution
What is the correct way to do this? 这样做的正确方法是什么?
The solution is using RelativeSource.TemplatedParent
解决方案是使用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.