0

エンティティを含むviewport3dと、そのエンティティの階層構造を含むツリービューがあります。Treeview は、次のようなクラス階層からバインドされます。

public class SomeDataObject
{
    private ObservableCollection<SomeDataObject> _children;
    private string _OtherProperty;

    public SomeDataObject()
    {
        this._children = new ObservableCollection<SomeDataObject>();
        //other initialization
    }

    public ObservableCollection<SomeDataObject> Children
    {
        get
        {
            return this._children;
        }
        set{ _children = value; }
    }

    public string OtherProperty
    {
        get
        {
            return this._OtherProperty;
        } 
        set{ _OtherProperty = value; }  
    }
}

階層なしで、すべてのオブジェクトの OtherProperty のみをビューポートにバインドしたいと思います。Viewport は ObservableCollection からのバインドを提供しますが、祖先は含まれません。したがって、下位レベルの OtherProperty にはアクセスできません。

2 つの別々のビューモデルについて考えていますが、異なるビューモデル間の通信を設計する方法がわかりません。

私はその解決策を見つけました: http://blog.quantumbitdesigns.com/2008/07/22/programmatically-selecting-an-item-in-a-treeview/ しかし、もちろんこれは回り道です。ビューモデルとモデルの変更を自動的に更新したいと思います。

そのような場合の最善の解決策は何ですか?

編集: これはツリービューの XAML です:

    <TreeView Grid.Column="0" Name="MainTreeView">
      <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type WpfTreeViewTricks:SomeDataObject}"  ItemsSource="{Binding Path=Children}">
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="TreeViewItem:"/>
            <TextBlock Margin="1,0,0,0" Text="{Binding Path=OtherProperty}"/>
          </StackPanel>
        </HierarchicalDataTemplate>
      </TreeView.Resources>
    </TreeView>

そして仕事です。

ここに画像の説明を入力

問題は、その階層構造をビューポートにバインドすることです。becase ビューポートでは、次の方法でバインドできます。

<ht:HelixViewport3D ItemsSource="{Binding Objects}" Background="{ht:LinearGradientBrush Gray, White}"/>

Objects は DataContext のプロパティです。

public ObservableCollection<Visual3D> Objects { get; set; }
4

0 に答える 0