I have a custom WPF control (using UserControl as base) that exposes a bindable properties (using DependencyProperty). I want to disable editing in this control when one of the properties is a oneway binding.
public partial class OnOffControl : UserControl
{
...
public static readonly DependencyProperty IsCheckedProperty =
DependencyProperty.Register(
"IsChecked",
typeof(bool?),
typeof(OnOffControl),
...
public bool? IsChecked
{
get
{
return (bool?)GetValue(IsCheckedProperty);
}
set
{
SetValue(IsCheckedProperty, value);
}
}
Usage point
<DataGridTemplateColumn Width="40" Header="State">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<UIUtil:OnOffControl
IndicatorType="SwitchIndicator"
IsChecked="{Binding Value, Mode=OneWay}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
So when IsChecked is a oneway binding I want to disable editing in OnOffControl. How does one go about detecting the property binding is OneWay inside of the control and then disable editing?
You may check if there is a Binding and get the Binding's properties in a PropertyChangedCallback: