Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The linked web page is for an unusual situation, a "push" binding. That is, a one-way-to-source binding was attempted on the read-only property, not on another property trying to bind to it. By contrast, if you want your property to be bindable to other properties <strong>using a one-way binding expression on the other property</strong>, then you can use a read-only dependency property without any issues.</p> <p><strong>Edit:</strong></p> <p>Here is an example:</p> <pre><code>&lt;Grid&gt; &lt;Grid.Resources&gt; &lt;local:MyObject x:Key="myObject" PropertyA="True" PropertyB="False"/&gt; &lt;/Grid.Resources&gt; &lt;StackPanel DataContext="{StaticResource myObject}"&gt; &lt;CheckBox IsChecked="{Binding PropertyA}" Content="PropertyA"/&gt; &lt;CheckBox IsChecked="{Binding PropertyB}" Content="PropertyB"/&gt; &lt;CheckBox IsChecked="{Binding PropertyC, Mode=OneWay}" IsEnabled="False" Content="PropertyC"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p>and the dependency properties, one of which is read-only:</p> <pre><code>public class MyObject : DependencyObject { public bool PropertyA { get { return (bool)GetValue(PropertyAProperty); } set { SetValue(PropertyAProperty, value); } } public static readonly DependencyProperty PropertyAProperty = DependencyProperty.Register("PropertyA", typeof(bool), typeof(MyObject), new UIPropertyMetadata(false, OnPropertyAOrBChanged)); public bool PropertyB { get { return (bool)GetValue(PropertyBProperty); } set { SetValue(PropertyBProperty, value); } } public static readonly DependencyProperty PropertyBProperty = DependencyProperty.Register("PropertyB", typeof(bool), typeof(MyObject), new UIPropertyMetadata(false, OnPropertyAOrBChanged)); public bool PropertyC { get { return (bool)GetValue(PropertyCProperty); } set { SetValue(PropertyCPropertyKey, value); } } private static readonly DependencyPropertyKey PropertyCPropertyKey = DependencyProperty.RegisterReadOnly("PropertyC", typeof(bool), typeof(MyObject), new UIPropertyMetadata()); public static readonly DependencyProperty PropertyCProperty = PropertyCPropertyKey.DependencyProperty; private static void OnPropertyAOrBChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var myObject = d as MyObject; myObject.PropertyC = myObject.PropertyA || myObject.PropertyB; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload