DataBinding

Jun 4, 2011 at 9:13 PM

Hi,

Is it possible to bind the NavigationPane a collection of items, that can then be styled to be a number of NavigationPaneItems ?

 

If so, is there an example of this in action ?

Cheers

Coordinator
Jun 5, 2011 at 1:22 PM

You can use the ItemsSource property to bind to data, the control will generate navigationpane items for each element in the ItemsSource
you can the use data templates ContentTemplate and ItemTemplate to specify how data are visualized:

<Window>
</Window.Resources>
<DataTemplate x:Key="DataTemplate1">
<Grid><TextBlock Text="{Binding}"/></Grid>
</DataTemplate>
<DataTemplate x:Key="DataTemplate2">
<Grid><TextBlock><Run Text="Content template for:"/><LineBreak/><Run Text="{Binding Mode=OneWay}"/></TextBlock></Grid>
</DataTemplate>
</Window.Resources>
 <Grid>
<s:NavigationPane ItemsSource="{Binding Resources.Keys, ElementName=window}" ContentTemplate="{DynamicResource DataTemplate2}" ItemTemplate="{DynamicResource DataTemplate1}"/>
</Grid>
</Window>

But you wont be able to have icons for the buttons.

Another solution would it be to directly create a collection of NavigationPaneItems and bind to it.
Or use the Items property and manually add and item for each source item in the collection.

Which kind of data contains the collection you want to bind ?
Is db data ?

If you need to have a dynamic loading of some prefixed number of items, you could examine the possibility of using MEF
Create a NavigationPaneItem to use with mef
MEF on MSDN

MEF if wath I've been using in the project for which I wrote the component !

Nov 5, 2011 at 9:38 PM

Hi,

Thank you for the sample code. I am new to WPF and am requesting you to kindly give me a sample code that helps me bind data to the navpanel.

Sample data I get from an XML is as below:

<workflow>
	<section name="section 1">
		<subsection name="subsection 1">
		<subsection name="subsection 2">
		<subsection name="subsection 3">
	</section>
	<section name="section 2">
		<subsection name="subsection 1">

	</section>
	<section name="section 3">
		<subsection name="subsection 1">
		<subsection name="subsection 2">
	</section>
	<section name="section 4">
		<subsection name="subsection 1">
		<subsection name="subsection 2">
		<subsection name="subsection 3">
	</section>
</workflow>

How do I create the NavPanelItems and its subitems using databinding ?
Thanks a lot!
-Rupesh

Nov 8, 2011 at 8:57 PM

I am creating the NavigationPaneItem in the viewmodel and sending them back to the view.. This is not working.. also, is this way acceptable ?

XAML

<s:NavigationPane ItemBindingGroup="{Binding Path=testMe}" ItemTemplate="{Binding Path=testMe}"                          SelectedIndex="0" LargeItems="2" Margin="2,0,0,1" Width="160"/>

ViewModel.cs

public ObservableCollection<NavigationPaneItem> testMe
        //public List<NavigationPaneItem> testMe
        {
            get
            {
                NavigationPaneItem x = new NavigationPaneItem();
                x.Header = "asdf";
                x.Content = "asasasasasa";

                _y.Add(x);

                _x = new ObservableCollection<NavigationPaneItem>(_y);
                return _x;
            }
        }

I tried both List and ObservableCollection. but I dont see any item added to the Navpane.

-Rupesh

Nov 8, 2011 at 9:44 PM

I did manage to get the code to work: However, when i click on any of the items in the navbar, nothing changes and all the buttons stay highlighted...

<s:NavigationPane ItemsSource="{Binding Path=testMe}" ContentTemplate="{DynamicResource DataTemplate2}" ItemTemplate="{DynamicResource DataTemplate1}"
                          SelectedIndex="0" LargeItems="2" Margin="2,0,0,1" Width="160"/>

Screenshot : http://r.upe.sh/pane.png 

-Rupesh

 

Coordinator
Nov 13, 2011 at 4:10 PM
mailrup wrote:

I did manage to get the code to work: However, when i click on any of the items in the navbar, nothing changes and all the buttons stay highlighted...

 

<s:NavigationPane ItemsSource="{Binding Path=testMe}" ContentTemplate="{DynamicResource DataTemplate2}" ItemTemplate="{DynamicResource DataTemplate1}"
                          SelectedIndex="0" LargeItems="2" Margin="2,0,0,1" Width="160"/>

 

Screenshot : http://r.upe.sh/pane.png 

-Rupesh

 


This was due to some issues with the databinding.
It has been fixed with latest checkins, togheter with some other issues with databinding.
I also updated the Documentation section adding an example on how to databind an xml file.

Stefano

Coordinator
May 17, 2012 at 12:59 PM

recently made fixes may solve this problem now,
please advise if the problem still persist :)
thanks