调整CNC树形结构风格,简化界面
This commit is contained in:
@@ -30,10 +30,11 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
private CncProgram _currentProgram;
|
||||
private ObservableCollection<CncNodeViewModel> _nodes;
|
||||
private ObservableCollection<CncNodeViewModel> _treeNodes;
|
||||
private ObservableCollection<CncProgramTreeRootViewModel> _programTreeRoots;
|
||||
private CncNodeViewModel _selectedNode;
|
||||
private bool _isModified;
|
||||
private string _programName;
|
||||
private string _programDisplayName = "NewCncProgram";
|
||||
private string _programDisplayName = "新建检测程序.xp";
|
||||
private Guid? _preferredSelectedNodeId;
|
||||
|
||||
public CncEditorViewModel(
|
||||
@@ -49,6 +50,10 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
|
||||
_nodes = new ObservableCollection<CncNodeViewModel>();
|
||||
_treeNodes = new ObservableCollection<CncNodeViewModel>();
|
||||
_programTreeRoots = new ObservableCollection<CncProgramTreeRootViewModel>
|
||||
{
|
||||
new CncProgramTreeRootViewModel(_programDisplayName, _treeNodes)
|
||||
};
|
||||
|
||||
InsertReferencePointCommand = new DelegateCommand(() => ExecuteInsertNode(CncNodeType.ReferencePoint));
|
||||
InsertSaveNodeWithImageCommand = new DelegateCommand(() => ExecuteInsertNode(CncNodeType.SaveNodeWithImage));
|
||||
@@ -85,6 +90,12 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
private set => SetProperty(ref _treeNodes, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<CncProgramTreeRootViewModel> ProgramTreeRoots
|
||||
{
|
||||
get => _programTreeRoots;
|
||||
private set => SetProperty(ref _programTreeRoots, value);
|
||||
}
|
||||
|
||||
public CncNodeViewModel SelectedNode
|
||||
{
|
||||
get => _selectedNode;
|
||||
@@ -114,7 +125,11 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
public string ProgramDisplayName
|
||||
{
|
||||
get => _programDisplayName;
|
||||
private set => SetProperty(ref _programDisplayName, value);
|
||||
private set
|
||||
{
|
||||
if (SetProperty(ref _programDisplayName, value) && ProgramTreeRoots?.Count > 0)
|
||||
ProgramTreeRoots[0].DisplayName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DelegateCommand InsertReferencePointCommand { get; }
|
||||
@@ -300,7 +315,7 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
|
||||
private void ExecuteNewProgram()
|
||||
{
|
||||
var name = string.IsNullOrWhiteSpace(ProgramName) ? "NewCncProgram" : ProgramName;
|
||||
const string name = "新建检测程序";
|
||||
_currentProgram = _cncProgramService.CreateProgram(name);
|
||||
ProgramName = _currentProgram.Name;
|
||||
ProgramDisplayName = FormatProgramDisplayName(_currentProgram.Name);
|
||||
@@ -427,6 +442,10 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
|
||||
Nodes = new ObservableCollection<CncNodeViewModel>(flatNodes);
|
||||
TreeNodes = new ObservableCollection<CncNodeViewModel>(rootNodes);
|
||||
ProgramTreeRoots = new ObservableCollection<CncProgramTreeRootViewModel>
|
||||
{
|
||||
new CncProgramTreeRootViewModel(ProgramDisplayName, TreeNodes)
|
||||
};
|
||||
|
||||
SelectedNode = selectedId.HasValue
|
||||
? Nodes.FirstOrDefault(node => node.Id == selectedId.Value) ?? Nodes.LastOrDefault()
|
||||
@@ -635,7 +654,7 @@ namespace XplorePlane.ViewModels.Cnc
|
||||
|
||||
private static string FormatProgramDisplayName(string programName)
|
||||
{
|
||||
var name = string.IsNullOrWhiteSpace(programName) ? "NewCncProgram" : programName;
|
||||
var name = string.IsNullOrWhiteSpace(programName) ? "新建检测程序" : programName;
|
||||
return name.EndsWith(".xp", StringComparison.OrdinalIgnoreCase) ? name : $"{name}.xp";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Prism.Mvvm;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace XplorePlane.ViewModels.Cnc
|
||||
{
|
||||
public class CncProgramTreeRootViewModel : BindableBase
|
||||
{
|
||||
private string _displayName;
|
||||
private bool _isExpanded = true;
|
||||
|
||||
public CncProgramTreeRootViewModel(string displayName, ObservableCollection<CncNodeViewModel> children)
|
||||
{
|
||||
_displayName = displayName;
|
||||
Children = children;
|
||||
}
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get => _displayName;
|
||||
set => SetProperty(ref _displayName, value);
|
||||
}
|
||||
|
||||
public bool IsExpanded
|
||||
{
|
||||
get => _isExpanded;
|
||||
set => SetProperty(ref _isExpanded, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<CncNodeViewModel> Children { get; }
|
||||
}
|
||||
}
|
||||
@@ -91,44 +91,53 @@
|
||||
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
Padding="10,8"
|
||||
Background="{StaticResource HeaderBg}"
|
||||
BorderBrush="{StaticResource SeparatorBrush}"
|
||||
BorderThickness="0,0,0,1">
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
FontFamily="{StaticResource UiFont}"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
Text="{Binding ProgramDisplayName, TargetNullValue=CNC编辑}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock
|
||||
Margin="0,3,0,0"
|
||||
FontFamily="{StaticResource UiFont}"
|
||||
FontSize="10"
|
||||
Foreground="#666666"
|
||||
Text="新建或加载已有的CNC检测程序,后缀.xp。"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<TreeView
|
||||
x:Name="CncTreeView"
|
||||
Grid.Row="1"
|
||||
Grid.Row="0"
|
||||
Padding="4,6"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
ItemsSource="{Binding TreeNodes}"
|
||||
ItemsSource="{Binding ProgramTreeRoots}"
|
||||
PreviewKeyDown="CncTreeView_PreviewKeyDown"
|
||||
SelectedItemChanged="CncTreeView_SelectedItemChanged">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type vm:CncNodeViewModel}" ItemsSource="{Binding Children}">
|
||||
<HierarchicalDataTemplate
|
||||
DataType="{x:Type vm:CncProgramTreeRootViewModel}"
|
||||
ItemContainerStyle="{StaticResource TreeItemStyle}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<Border
|
||||
Margin="0,1,0,3"
|
||||
Padding="2,4"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="2,0,6,0"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{StaticResource UiFont}"
|
||||
FontSize="13"
|
||||
Foreground="#2B8A3E"
|
||||
Text="◆" />
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{StaticResource UiFont}"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
Text="{Binding DisplayName}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
<HierarchicalDataTemplate
|
||||
DataType="{x:Type vm:CncNodeViewModel}"
|
||||
ItemContainerStyle="{StaticResource TreeItemStyle}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<Border
|
||||
x:Name="NodeCard"
|
||||
Margin="0,1,0,1"
|
||||
|
||||
Reference in New Issue
Block a user