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