I have my own custom control using DependencyProperty IsBusy
Here is how I use it:
<Controls:myToolbar Grid.ColumnSpan="5" Mode="DataEntry" Status="{Binding State, Converter={StaticResource ViewEditingStateToToolbarStateConverter}}" IsBusy="{Binding IsBusy}"/>
By convention, all my VMs inherit from the base VM and have the IsBusy property. So, I KNOW that this property will always be available in the virtual machine.
Now I have 4 more properties like this. Instead of adding them to XAML in all of my views, I want to know how to bind to this internal IsBusy control code, so I donโt need to bind to XAML?
EDIT
In fact, I found the answer to my question: Silverlight: programmatically binding control properties
Now, my question is:
Is it correct to apply this binding in a constructor like this?
public myToolbar() { this.DefaultStyleKey = typeof(myToolbar); var binding = new Binding("IsBusy") { Mode = BindingMode.TwoWay }; this.SetBinding(IsBusyProperty, binding); }
Should I check if there is a XAML binding (another obligation) to this property and is not bound? It works anyway, but I wonder if this is bad for performance, smells, etc.?
How to do it in onApplyTemplate . Is this the best way?
if (GetBindingExpression(IsBusyProperty) == null) { var binding = new Binding("IsBusy") { Mode = BindingMode.TwoWay }; this.SetBinding(IsBusyProperty, binding); }
c # silverlight binding xaml custom-controls
katit
source share