silverlight 4 treeview silently throws Binding Errors

837 Views Asked by At

So I have a silverlight treeview control bound to the type below, I set the DataContext of my page to an instance of my ViewModel which has a Divisions property that is a List of RmDivision objects.

public class RmDivision
    {
        public RmDivision()
        {
            SubDivisions = new ObservableCollection<RmDivision>();
        }
        public string Type { get; set; }
        public string Name { get; set; }
        public IList<RmDivision> SubDivisions { get; set; }
    }

And then its bound like this:

 <sdk:TreeView HorizontalAlignment="Stretch" Name="treeBranches" 
                          ItemsSource="{ Binding Divisions }"  VerticalAlignment="Stretch" SelectedValuePath="Division" Grid.Row="0" SelectedItemChanged="treeBranches_SelectedItemChanged">
                <sdk:TreeView.ItemTemplate>
                    <sdk:HierarchicalDataTemplate  ItemsSource="{Binding SubDivisions}">
                        <TextBlock Text="{Binding Name}" ToolTipService.ToolTip="{Binding Type}" />
                    </sdk:HierarchicalDataTemplate>
                </sdk:TreeView.ItemTemplate>
            </sdk:TreeView>

Now, I get no exceptions, everytime I click a treeeview item, only in my output window I see:

System.Windows.Data Error: BindingExpression path error: 'Division' property not found on 'xxx.Base.RmDivision' 'xxx.Base.RmDivision' (HashCode=35753827). BindingExpression: Path='Division' DataItem='xxx.Base.RmDivision' (HashCode=35753827); target element is 'System.Windows.Controls.ContentControl' (Name=''); target property is 'Content' (type 'System.Object')..

I'm kinda a newbie here and don't really know what is going on, the only way I know it is the treeview is because thats the only control that has to do anything with a Division property, is it the SelectedValuePath, I want the SelectedItem to be an instance of RmDivision and current it works like this.

Regards

1

There are 1 best solutions below

4
On BEST ANSWER

Division is not a property of RmDivision. So every time you select a treeviewitem it will try to lookup the property and it can't find it.