105040 优化界面样式

This commit is contained in:
lihanbo 2024-12-03 16:10:44 +08:00
parent 2740456d41
commit 698c23fcdb
4 changed files with 63 additions and 40 deletions

View File

@ -32,7 +32,7 @@
</DataTemplate> </DataTemplate>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid Margin="10"> <Grid Margin="0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="60" /> <RowDefinition Height="60" />
@ -55,6 +55,7 @@
x:Name="InfoCard" x:Name="InfoCard"
Grid.Row="0" Grid.Row="0"
Grid.Column="0" Grid.Column="0"
hc:BorderElement.CornerRadius="0,0,0,5"
Effect="{DynamicResource EffectShadow2}" Effect="{DynamicResource EffectShadow2}"
FontSize="14"> FontSize="14">
<hc:SimpleStackPanel <hc:SimpleStackPanel
@ -206,18 +207,24 @@
<hc:Card <hc:Card
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
hc:BorderElement.CornerRadius="0,0,5,0"
Effect="{DynamicResource EffectShadow2}"> Effect="{DynamicResource EffectShadow2}">
<DataGrid <DataGrid
x:Name="SelectedLines_Dg"
MinHeight="200" MinHeight="200"
hc:BorderElement.CornerRadius="0,0,5,0"
AutoGenerateColumns="False" AutoGenerateColumns="False"
Background="{StaticResource BackgroundBrush}" Background="{StaticResource BackgroundBrush}"
CanUserAddRows="False" CanUserAddRows="False"
FontSize="14" FontSize="14"
IsReadOnly="True"
ItemsSource="{Binding SelectedLines}" ItemsSource="{Binding SelectedLines}"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="NaN" RowHeight="NaN"
ScrollViewer.CanContentScroll="False"> ScrollViewer.CanContentScroll="False"
VirtualizingPanel.IsVirtualizing="False"
VirtualizingPanel.ScrollUnit="Pixel">
<DataGrid.RowStyle> <DataGrid.RowStyle>
<Style BasedOn="{StaticResource DataGridRowStyle}" TargetType="DataGridRow"> <Style BasedOn="{StaticResource DataGridRowStyle}" TargetType="DataGridRow">
<Setter Property="Foreground" Value="White" /> <Setter Property="Foreground" Value="White" />
@ -300,6 +307,7 @@
PreviewMouseWheel="ListView_PreviewMouseWheel" PreviewMouseWheel="ListView_PreviewMouseWheel"
ScrollViewer.CanContentScroll="True" ScrollViewer.CanContentScroll="True"
SelectionMode="Single" SelectionMode="Single"
VirtualizingPanel.IsVirtualizing="False"
VirtualizingPanel.ScrollUnit="Pixel"> VirtualizingPanel.ScrollUnit="Pixel">
<ListView.View> <ListView.View>
<GridView> <GridView>
@ -340,7 +348,7 @@
Click="SaveBtn_Click" Click="SaveBtn_Click"
Content="保存" Content="保存"
FontSize="14" FontSize="14"
Style="{StaticResource ButtonPrimary}" /> Style="{StaticResource ButtonSuccess}" />
<Button <Button
Margin="10,0,10,0" Margin="10,0,10,0"
hc:IconElement.Geometry="{StaticResource CloseGeometry}" hc:IconElement.Geometry="{StaticResource CloseGeometry}"

View File

@ -34,13 +34,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
set set
{ {
_motor = (MotorModel)value; _motor = (MotorModel)value;
_viewModel.Motor = _motor; ViewModel.Motor = _motor;
SetValue(MotorProperty, value); SetValue(MotorProperty, value);
} }
} }
private CableLectotypeViewModel _viewModel; private CableLectotypeViewModel ViewModel = new CableLectotypeViewModel();
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@ -53,45 +53,39 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
public CableLectotypeWindow() public CableLectotypeWindow()
{ {
InitializeComponent(); InitializeComponent();
this.Initialized += CableLectotypeWindow_Initialized;
}
private void CableLectotypeWindow_Initialized(object sender, EventArgs e) Debug.WriteLine($"CableLectotypeWindow_Created -> {_motor?.MotorModelStr} => {_motor?.OccPartId}");
{
OnMotorChanged();
Debug.WriteLine($"Page_Loaded -> {_motor?.MotorModelStr} => {_motor?.OccPartId}");
} }
private void OnMotorChanged() private void OnMotorChanged()
{ {
_motor = (Motor as MotorModel); _motor = (Motor as MotorModel);
if (_motor != null) if (_motor != null)
this.Dispatcher.BeginInvoke(() => try
{ {
try LoadingContentMask.Visibility = Visibility.Visible;
var oldViewModel = LectotypeViewModelFactory.CreateOrGetAsync(_motor).Result;
if (oldViewModel != null)
{ {
LoadingContentMask.Visibility = Visibility.Visible; ViewModel.Apply(oldViewModel);
_viewModel = LectotypeViewModelFactory.CreateOrGetAsync(_motor).Result;
//if(_viewModel == null)
//{
// _viewModel = new
//}
this.DataContext = _viewModel;
} }
catch (Exception ex) this.DataContext = ViewModel;
{ //SelectedLines_Dg.Dispatcher.
Debug.WriteLine(ex.ToString()); }
} catch (Exception ex)
finally {
{ Debug.WriteLine(ex.ToString());
LoadingContentMask.Visibility = Visibility.Collapsed; }
} finally
}); {
LoadingContentMask.Visibility = Visibility.Collapsed;
}
} }
private void CableratorBtn_Click(object sender, RoutedEventArgs e) private void CableratorBtn_Click(object sender, RoutedEventArgs e)
{ {
_viewModel.Cablerator(); ViewModel.Cablerator();
} }
private void ListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) private void ListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
@ -111,8 +105,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{ {
OnMotorChanged();
Debug.WriteLine($"Page_IsVisibleChanged -> {(Motor as MotorModel)?.MotorModelStr} => {(Motor as MotorModel)?.OccPartId}"); Debug.WriteLine($"Page_IsVisibleChanged -> {(Motor as MotorModel)?.MotorModelStr} => {(Motor as MotorModel)?.OccPartId}");
//OnMotorChanged();
} }
private void SaveBtn_Click(object sender, RoutedEventArgs e) private void SaveBtn_Click(object sender, RoutedEventArgs e)
@ -120,7 +114,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
LoadingContentMask.Visibility = Visibility.Visible; LoadingContentMask.Visibility = Visibility.Visible;
try try
{ {
if (_viewModel.SaveToDb()) if (ViewModel.SaveToDb())
{ {
Growl.Success("保存成功", "CableLectotypeMessage"); Growl.Success("保存成功", "CableLectotypeMessage");
} }

View File

@ -181,17 +181,33 @@
<TabItem Header="电机数据"> <TabItem Header="电机数据">
<ListBox <ListBox
x:Name="MotorListView" x:Name="MotorListView"
Padding="0"
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Motors}" ItemsSource="{Binding Motors}"
ScrollViewer.CanContentScroll="False" ScrollViewer.CanContentScroll="False"
VirtualizingPanel.ScrollUnit="Pixel"> VirtualizingPanel.ScrollUnit="Pixel">
<ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource ListBoxItemBaseStyle}" TargetType="ListBoxItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Resources> <ListBox.Resources>
<Style TargetType="ListBoxItem"> <Style BasedOn="{StaticResource ExpanderBaseStyle}" TargetType="Expander">
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="MinHeight" Value="50" />
<Setter Property="Margin" Value="2" />
<Style.Triggers> <Style.Triggers>
<Trigger Property="IsSelected" Value="True"> <Trigger Property="IsExpanded" Value="True">
<Setter Property="Foreground" Value="{StaticResource LightPrimaryBrush}" />
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
</Trigger> </Trigger>
<DataTrigger Binding="{Binding IsError}" Value="True">
<Setter Property="Background" Value="#dc4d41" />
<Setter Property="Foreground" Value="White" />
</DataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</ListBox.Resources> </ListBox.Resources>
@ -207,7 +223,7 @@
<!-- Expander 的标题部分 --> <!-- Expander 的标题部分 -->
<Expander.Header> <Expander.Header>
<!-- 使用 Grid 定义列布局 --> <!-- 使用 Grid 定义列布局 -->
<Grid> <Grid MinHeight="50">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="160" MinWidth="160" /> <ColumnDefinition Width="160" MinWidth="160" />
<ColumnDefinition Width="160" MinWidth="160" /> <ColumnDefinition Width="160" MinWidth="160" />
@ -241,7 +257,8 @@
Grid.Column="4" Grid.Column="4"
VerticalAlignment="Center" VerticalAlignment="Center"
Orientation="Horizontal"> Orientation="Horizontal">
<Button Click="SelectedLectotype_Click" Content="展开线材选型" /> <!-- Click="SelectedLectotype_Click" -->
<ToggleButton Content="展开线材选型" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType=Expander}}" />
</StackPanel> </StackPanel>
<!-- ID --> <!-- ID -->
<TextBlock Grid.Column="5" Text="{Binding OccPartId}" /> <TextBlock Grid.Column="5" Text="{Binding OccPartId}" />

View File

@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Security.RightsManagement;
using System.Windows.Shapes; using System.Windows.Shapes;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
@ -205,7 +206,10 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
OnPropertyChanged(nameof(SelectedLines)); OnPropertyChanged(nameof(SelectedLines));
} }
} }
public CableLectotypeViewModel()
{
}
public CableLectotypeViewModel(MotorModel motor) public CableLectotypeViewModel(MotorModel motor)
{ {
Motor = motor; Motor = motor;
@ -335,16 +339,16 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
{ {
return; return;
} }
Motor = viewModel.Motor;
CableConnectionType = viewModel.CableConnectionType; CableConnectionType = viewModel.CableConnectionType;
AxisNo = viewModel.AxisNo; AxisNo = viewModel.AxisNo;
CableType = viewModel.CableType; CableType = viewModel.CableType;
EncoderLineParagraph = viewModel.EncoderLineParagraph; EncoderLineParagraph = viewModel.EncoderLineParagraph;
PowerLineParagraph = viewModel.PowerLineParagraph; PowerLineParagraph = viewModel.PowerLineParagraph;
CableModelStr = viewModel.CableModelStr; CableModelStr = viewModel.CableModelStr;
SelectedLines = [];
// 深拷贝 SelectedLines // 深拷贝 SelectedLines
SelectedLines = viewModel.SelectedLines.Select(line => new LectotypeLineModel SelectedLines.AddRange(viewModel.SelectedLines.Select(line => new LectotypeLineModel
{ {
SeqNo = line.SeqNo, SeqNo = line.SeqNo,
MechanicalNo = line.MechanicalNo, MechanicalNo = line.MechanicalNo,
@ -367,7 +371,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
CableModel = subLine.CableModel, CableModel = subLine.CableModel,
CableType = subLine.CableType CableType = subLine.CableType
}).ToList() }).ToList()
}).ToList(); }).ToList());
OnPropertyChanged(nameof(SelectedLines)); OnPropertyChanged(nameof(SelectedLines));
} }