TreeView с несколькими шаблонами с Caliburn Micro wpf - PullRequest
0 голосов
/ 22 января 2020

У меня проблема с моим деревом. Я пытаюсь использовать его трехслойную структуру, но каким-то образом, когда я соединяю высокоуровневые шаблоны вместе с узлом root, даже если он содержит дочерние элементы, он не показывает кнопку расширения или не позволяет мне развернуть ее.

I сделал мой шаблон вокруг этой статьи Несколько шаблонов TreeView

Итак, мой xaml выглядит так:

<TreeView Grid.Row="1" Grid.Column="1" MinWidth="150"
                          ItemsSource="{Binding Operations}" Name="Operations">
                    <TreeView.Resources>
                        <HierarchicalDataTemplate DataType="{x:Type local:Operation}" ItemsSource="{Binding Operation}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Name}" />
                                <TextBlock Text=" " ></TextBlock>
                                <TextBlock Text="{Binding Parameters.Count}" />
                            </StackPanel>
                        </HierarchicalDataTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type local:Parameters}" ItemsSource="{Binding Parameters}">
                            <StackPanel>
                                <TextBlock Text="{Binding Path=par}" ToolTip="{Binding Path=Path}" />
                                <TextBlock Text="{Binding Path=val}" ToolTip="{Binding Path=Path}" />
                            </StackPanel>
                        </HierarchicalDataTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type local:Joints}" ItemsSource="{Binding Joints}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Par}" />
                                <TextBlock Text=" " ></TextBlock>
                                <TextBlock Text="{Binding Val}" />
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </TreeView.Resources>
                    <TreeView.ItemContainerStyle>
                        <Style TargetType="TreeViewItem">
                            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        </Style>
                    </TreeView.ItemContainerStyle>
                </TreeView>

У меня есть отдельные классы для операций, параметров и соединений, которые выглядят как это:

Операции:

    public class Operation
{
    public string Name { get; set; }
    public int Id { get; set; }

    public ObservableCollection<Parameters> Parameters { get; set; }

    public Operation()
    {
        Parameters = new ObservableCollection<Parameters>();
    }
}

Параметры:

    public class Parameters
{
    public string par { get; set; }
    public double val { get; set; }

    public ObservableCollection<Joints> Joints { get; set; }

    public Parameters()
    {
        Joints = new ObservableCollection<Joints>();
    }
}

Соединения:

    public class Joints
{
    public string Par { get; set; }
    public double Val { get; set; }
}

Мой ShellViewModel, который реализует все эти классы в выглядит так:

public BindableCollection<Operation> _Operations = new BindableCollection<Operation>();


private bool _IsExpanded;
public bool IsExpanded
{
    get 
    { return _IsExpanded; }
    set 
    { 
        _IsExpanded = value;
        NotifyOfPropertyChange(() => IsExpanded);
    }
}
private bool _IsSelected;
public bool IsSelected
{
    get { return _IsSelected; }
    set 
    { 
        _IsSelected = value;
        NotifyOfPropertyChange(() => IsSelected);
    }
}

public Operation _Operation = new Operation();
int moveId = 0;

public BindableCollection<Operation> Operations
{
    get { return _Operations; }
    set 
    { 
        _Operations = value;
        NotifyOfPropertyChange(() => Operations);
    }
}

public ShellViewModel()
{

var moveOperation = new Operation
    {
        Id = moveId,
        Name = $"Move{moveId}"
    };
    Joints jt1 = new Joints() { Par = "J0", Val = 2.34 };
    Joints jt2 = new Joints() { Par = "J1", Val = 0.34 };
    Joints jt3 = new Joints() { Par = "J2", Val = 4.34 };
    Parameters parm = new Parameters { par = "a", val = 2.13 };
    parm.Joints.Add(jt1);
    parm.Joints.Add(jt2);
    parm.Joints.Add(jt3);
    moveOperation.Parameters.Add(parm);
    _Operations.Add(moveOperation);

Ожидаемый результат примерно такой:

 - Move1
    -a 2.13
    -Joints
      -J0 2.34
      -J1 0.34
      -J2 4.34
 - Move2
    -a 'some value'
    -Joints
      -J0 'some value'
      -J1 'some value'
      -J2 'some value'

Чего мне не хватает? Почему я не вижу больше, чем только мой корневой \ родительский \ рабочий узел? И я не могу его расширить.

...