Another Databinding issue

May 16, 2012 at 8:44 PM

I have created a simple test application to test the databinding functionality of the Navigation Pane Control.

Here is the xaml:

 

<Window x:Class="OutlookNavigationPanelTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="http://www.stemasoft.com/xaml"
        Title="MainWindow" Height="600" Width="300">

    <Window.Resources>

        <DataTemplate x:Key="DataTemplate1">
            <TextBlock Text="{Binding Path=Name}"></TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="DataTemplate2">
            <StackPanel>
                <TextBlock Text="{Binding Path=Name}"></TextBlock>
                <ListBox ItemsSource="{Binding Path=Rows}">
                </ListBox>
            </StackPanel>
        </DataTemplate>

    </Window.Resources>

    <Grid>
        <s:NavigationPane x:Name="navigationPane"  IsMinimizeButtonVisible="False" 
                ItemTemplate="{DynamicResource DataTemplate1}"
				ContentTemplate="{DynamicResource DataTemplate2}">
            <s:NavigationPane.ItemsButtonsContextMenu>
                <ContextMenu>
                    <s:ConfigureMenuItem MenuType="Options" />
                </ContextMenu>
            </s:NavigationPane.ItemsButtonsContextMenu>
        </s:NavigationPane>
    </Grid>
</Window>

 

And here is the code behind:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Stema.Controls;
using System.Collections.ObjectModel;

namespace OutlookNavigationPanelTest
{
    class Table
    {
        private string _Name = "";
        private List<string> _Rows = new List<string>();

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public List<string> Rows
        {
            get { return _Rows; }
            set { _Rows = value; }
        }

        public Table(string aName, List<string> aRows)
        {
            Name = aName;
            Rows = aRows;
        }

    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            navigationPane.ItemsSource = GenerateTestContent();
        }

        private ObservableCollection<Table> GenerateTestContent()
        {
            ObservableCollection<Table> result = new ObservableCollection<Table>();

            List<string> rows;
            Table t;

            for (int i = 1; i < 5; i++)
			{
                rows = new List<string>();
                t = null;

                for (int j = 1; j < 10; j++)
			    {
			        rows.Add(string.Format("Table #{0} - Row #{1}", i.ToString(), j.ToString()));
			    }

                t = new Table(string.Format("Table #{0}", i.ToString()), rows);

                if (t != null)
                    result.Add(t);
            }

            return result;
        }
    }
}

As you can see I am simply binding my NavigationPane to an ObservableCollection of a simple object I created called Table. When I run this the first item in the collection seems to render properly however clicking any of the other items in the pane shows no changes and all the buttons stay highlighted. (Just like mailrup reported here). I have downloaded the latest source and this does not seem to fix the problem. Did I miss something or is the databinding still not working properly?

 

Developer
May 17, 2012 at 10:47 AM

Seems to be due to a bug or similar in the dot net 4 regarding {DisconnectedItem}, a 'sentinel object'... more informations here:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/36aec363-9e33-45bd-81f0-1325a735cc45/#611fccf2-737f-4309-a793-4001488b23aa

I've triyed your code and the first thing i noticed is that there are 4 items in the list, which are the first two items. the fist and the third are {DisconnectedItem} ( and causing a lot of problems :( ) clicking on those does nothing.

I'm triyng to get a work around as ignore any object of type {DisconnectedItem}

Coordinator
May 17, 2012 at 1:04 PM

last checkin ( just made ) as a temp fix for this problem, it should solve
let me know if there are still problems with databinng the control as it solves it

May 17, 2012 at 4:19 PM

The latest checkin seems to resolve the issue, thanks.

Now I am running into an additional issue where when I click on the menu button I get a Null Reference error on the IsItemExcludedProperty. I'm not sure how to set NavigationPaneItem properties like that through the binding. I'm assuming there is no easy way just like you can't set the Image and ImageSmall properties, so I think I am just going to loop through my ObservableCollection of tables and build the NavigationPaneItem in the code-behind and then bind them to the NavigationPane.

Please let me know if there is a way to bind to all of the NavigationPaneItem properties (even if I have to add equivalent properties to my Table object) because binding the underlying data object is still preferable to me over looping through and creating the NavigationPaneItem manually.