0

UserControl を実装し、その上に TreeView コントロールを配置しました。XAML ファイルは次のようになります。Treeview とのデータ バインディングに HierarchicalDataTemplate を使用しています。

<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>

次のように、データ クラスを TreeView にバインドしています。

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;
            }
        }
    }
}

しかし、このコードをコンパイルすると、次のエラーが発生します。

エラー MC1000: 不明なビルド エラー、「型 'System.ComponentModel.IEditableCollectionView' をアセンブリ 'WindowsBase、Version=3.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35' から読み込めませんでした」。行 9 位置 87.' xaml ファイルで。

XAML ファイルに HierarchicalDataTemplate を含むコードをコメントすると、プロジェクトはエラーなしでコンパイルされます。コンパイルエラーを超えている理由がわかりません。

これについて私を助けてください。

4

3 に答える 3

0

3.5 フレームワークをターゲットにする必要があるだけではありませんか? または、SP2 of 3.0 がインストールされていることを確認してください。

于 2009-01-12T12:22:37.730 に答える
0

あなたの例からコンパイルソリューションを作成できます。

このエラーは、プロジェクトのターゲットとインストールされているフレームワークなどの間でバージョンが一致していないことを意味している可能性があります。

もう 1 つの問題は、PC への一般的なホース フレームワークのインストールである可能性があります。クリーン インストールでエラーを再現してみてください。

于 2009-01-12T12:23:23.033 に答える
0

解決しました...windowsbase.dllの不一致がありました...

于 2009-01-13T05:08:47.373 に答える