views:

745

answers:

4

Hi,

I have implemented a UserControl and put a TreeView control on that. The XAML file looks as follows. I am using a HierarchicalDataTemplate for data binding with the Treeview,

<UserControl x:Class="Trinity.Windows.Viewer.Alarm.AlarmPage.TrinityDeviceTree"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src ="clr-namespace:Trinity.Windows.Viewer.Alarm.AlarmPage" 
    Height="300" Width="300">
    <UserControl.Resources>
        <src:SiteList x:Key="SiteListKey"/>
        <HierarchicalDataTemplate DataType="{x:Type src:Site}" 
            ItemsSource="{Binding Path=PartitionsList}">
        <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="{x:Type src:Partition}" 
        ItemsSource="{Binding Path=MasterDeviceList}">
        <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="{x:Type src:MasterDevice}" 
        ItemsSource="{Binding Path=SlaveDeviceList}">
        <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>

    <DataTemplate DataType="{x:Type src:SlaveDevice}">
        <TextBlock Text="{Binding Path=Name}"/>
    </DataTemplate> 
</UserControl.Resources>

<Grid Width="auto" Height="auto">
    <Grid.RowDefinitions>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <TreeView Name="DeviceTree"/>
</Grid>

I have data classes bound to the TreeView as follows:

namespace Trinity.Windows.Viewer.Alarm.AlarmPage
{

    public class Site
    {
        public Site(string name)
        {
            _name = name;
            _partitions = new ObservableCollection<Partition>();
        }
        string _name;
        public string Name { get { return _name; } }
        ObservableCollection<Partition> _partitions;
        public List<Partition> PartitionsList { get { return _partitions; } }
    }

    public class Partition
    {
        public Partition(string name)
        {
            _name = name;
            _masterdevice = new ObservableCollection<MasterDevice>();
        }
        string _name;
        public string Name { get { return _name; } }
        ObservableCollection<MasterDevice> _masterdevice;
        public ObservableCollection<MasterDevice> MasterDeviceList { get { return _masterdevice; } }
    }

    public class MasterDevice
    {
        public MasterDevice(string name)
        {
            _name = name;
            _slavedevice = new ObservableCollection<SlaveDevice>();
        }
        string _name;
        public string Name { get { return _name; } }
        ObservableCollection<SlaveDevice> _slavedevice;
        public ObservableCollection<SlaveDevice> SlaveDeviceList { get { return _slavedevice; } }
    }

    public class SlaveDevice
    {
        public SlaveDevice(string name)
        {
            _name = name;
        }

        string _name;

        public string Name { get { return _name; } }
    }

    public class SiteList : ObservableCollection<Site>
    {
        public Site this[string name]
        {
            get
            {
                foreach (Site objSite in this)
                    if (objSite.Name == name)
                        return objSite;
                return null;
            }
        }
    }
}

But now when I compile this code I get following error:

error MC1000: Unknown build error, 'Could not load type 'System.ComponentModel.IEditableCollectionView' from assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Line 9 Position 87.' in xaml file.

Now if I comment code containing HierarchicalDataTemplate in the XAML file, my projects compiles without error's. I am not getting why I am getting above compilation error.

Please help me on this.

A: 

Don't you just need to target the 3.5 Framework? Or make sure you have SP2 of 3.0 installed.

Steven Robbins
http://msdn.microsoft.com/en-us/library/system.componentmodel.ieditablecollectionview.aspx says that this interface is supported already in 3.0 SP2
David Schmitt
3.5SP1 and 3.0SP2 I think.. perhaps you're missing the service pack?
Steven Robbins
A: 

I could create a compiling solution from your example.

The error could mean a version mismatch between your project's target and installed frameworks or similar.

Another problem might be a generally hosed framework installation on your PC. Try to reproduce the error on a clean installation.

David Schmitt
A: 

Thanks for answering I have .net 3.5 installed with SP1...and i think 3.5 sp1 contains .net 3.0 sp2 also...What could be other reason ?

A: 

Got it resolved...There was windowsbase.dll mismatch...