Reputation: 1566
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).
My AsyncCommand
has Execution
property and it has IsNotCompleated
property. I want to set Visibility
property of loader indincator using IsNotCompleted
property.
I create UserControl inherits the Button
and set style for this. I try to bind visibility to Button's Command
dependency property.
There the part of ControlTemplate
with "Loading indicator" (I use content, not Visibility, just for example)
<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:
Command.Execution
What is the correct way to do this?
Upvotes: 2
Views: 758
Reputation: 1566
The solution is using RelativeSource.TemplatedParent
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.Column="1"
Content="{Binding Command.Execution.IsNotCompleted, RelativeSource={RelativeSource TemplatedParent}}"/>
Upvotes: 3