Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make custom class bindable in WPF?
    primarykey
    data
    text
    <p>I have a class,</p> <pre><code>internal class PageInformation : DependencyObject { public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(PageInformation)); public static DependencyProperty PageUriProperty = DependencyProperty.Register("PageUri", typeof(string), typeof(PageInformation)); public string Name { get; set; } public Uri PageUri { get; } } </code></pre> <p>How can I bind it to some data source?</p> <p>My idea is to have an XML file which stores the information about all the pages in the application, have this class in <code>&lt;Page.Resources&gt;</code> and bind it to the XML file.</p> <p>The XML file looks like this:</p> <pre><code>&lt;Elements&gt; &lt;Element Name="Administration" DisplayName="Administration" Value="1" PageUri="Administration.xaml" &gt; &lt;Element Name="Categories" DisplayName="Categories" Value="2" PageUri="Administration.xaml" &gt;&lt;/Element&gt; &lt;Element Name="Goals" DisplayName="Goals" Value="3" PageUri="Administration.xaml" &gt;&lt;/Element&gt; &lt;Element Name="Settings" DisplayName="Settings" Value="4" PageUri="Administration.xaml" &gt;&lt;/Element&gt; &lt;/Element&gt; &lt;/Elements&gt; </code></pre> <p>I want to have have the XAML like this:</p> <pre><code> &lt;Page.Resources&gt; &lt;local:PageInformation x:Key="pageInfo" Name="{Binding XPath=/Elements/Element[@Name='Administration']}" Source="/samples.xml" &gt; &lt;/local:PageInformation&gt; &lt;/Page.Resources&gt; </code></pre> <p>When I have value for <code>Name</code> property, I want to write code to populate other properties as well (probably by using the data context?).</p> <p>Can somebody tell me how can I achieve this?</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.
    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