Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Control's Nested property's data binding
    primarykey
    data
    text
    <p>I'm trying to develop user control with some nested properties that allows to use databinding to set it. For example, I have something like this:</p> <pre><code>// Top level control public class MyControl : Control { public string TopLevelTestProperty { get { return (string)GetValue(TopLevelTestPropertyProperty); } set { SetValue(TopLevelTestPropertyProperty, value); } } public static readonly DependencyProperty TopLevelTestPropertyProperty = DependencyProperty.Register("TopLevelTestProperty", typeof(string), typeof (MyControl), new UIPropertyMetadata("")); // This property contains nested object public MyNestedType NestedObject { get { return (MyNestedType)GetValue(NestedObjectProperty); } set { SetValue(NestedObjectProperty, value); } } public static readonly DependencyProperty NestedObjectProperty = DependencyProperty.Register("NestedObject", typeof(MyNestedType), typeof (MyControl), new UIPropertyMetadata(null)); } // Nested object's type public class MyNestedType : DependencyObject { public string NestedTestProperty { get { return (string)GetValue(NestedTestPropertyProperty); } set { SetValue(NestedTestPropertyProperty, value); } } public static readonly DependencyProperty NestedTestPropertyProperty = DependencyProperty.Register("NestedTestProperty", typeof(string), typeof (MyNestedType), new UIPropertyMetadata("")); } // Sample data context public class TestDataContext { public string Value { get { return "TEST VALUE!!!"; } } } ... this.DataContext = new TestDataContext(); ... </code></pre> <p>XAML:</p> <pre><code> &lt;local:mycontrol x:name="myControl" topleveltestproperty="{Binding Value}" &gt; &lt;local:mycontrol.nestedobject&gt; &lt;local:mynestedtype x:name="myNestedControl" nestedtestproperty="{Binding Value}" /&gt; &lt;/local:mycontrol.nestedobject&gt; &lt;/local:mycontrol&gt; </code></pre> <p>It works well for property TopLevelTestProperty, but it doesn't work for NestedTestProperty. It seems that nested bindings do not work. Can anybody help me please? Is there any way to make such binding? I think that it happens because of my nested object has no any reference to the top level object, so it cannot be resolved using MyControl's DataContext.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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