Files
CapMachine/CapMachine.Shared/Controls/Meter.xaml
Tyrone CT 34ec76fda5 SV2功能增加
一些功能的修复
2025-05-21 12:17:46 +08:00

262 lines
13 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<UserControl
x:Class="CapMachine.Shared.Controls.Meter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CapMachine.Shared.Controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MeterInstance"
Width="82"
Height="155"
BorderBrush="Gray"
mc:Ignorable="d">
<materialDesign:Card
Margin="0,1"
Background="{DynamicResource MaterialDesignLightBackground}"
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
UniformCornerRadius="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2.2*" />
<RowDefinition Height="3*" />
<RowDefinition Height="1.2*" />
</Grid.RowDefinitions>
<Border
Margin="1,3,1,0"
Background="#404040"
CornerRadius="3" />
<StackPanel Margin="1,3,1,0">
<DockPanel Margin="1,5,1,2">
<TextBlock
Margin="1,0,1,0"
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="13"
Foreground="White"
Text="PV" />
<TextBlock
Margin="1,0,0,0"
VerticalAlignment="Center"
FontSize="13"
Foreground="White"
Text="{Binding ElementName=MeterInstance, Path=PVValue}" />
<TextBlock
Margin="0,0,1,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
DockPanel.Dock="Right"
FontSize="10"
Foreground="White"
Text="{Binding ElementName=MeterInstance, Path=Unit}" />
</DockPanel>
<DockPanel Margin="1,0,0,0">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="16"
FontStyle="Italic"
Foreground="Gold"
Text="SV" />
<TextBlock
Margin="6,0,0,0"
VerticalAlignment="Center"
FontSize="16"
Foreground="Gold"
Text="{Binding ElementName=MeterInstance, Path=SVValue}" />
<!--<TextBlock
Margin="2,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
DockPanel.Dock="Right"
FontSize="12"
Foreground="Gold"
Text="{Binding ElementName=MeterInstance, Path=Unit}" />-->
</DockPanel>
</StackPanel>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="0.5*" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- 手自动切换 -->
<StackPanel Margin="5,3,3,0" Orientation="Horizontal">
<!--
Command="{Binding ElementName=MeterInstance, Path=AutoHandCommand}"
CommandParameter="{Binding ElementName=MeterInstance}"
把整个控件作为参数传递进去
-->
<!-- Width="40" -->
<ToggleButton
x:Name="ToggleBtnAutoHand"
Width="40"
Click="ToggleBtnAutoHand_Click_1"
Command="{Binding ElementName=MeterInstance, Path=AutoHandCommand}"
CommandParameter="{Binding ElementName=MeterInstance}"
IsChecked="{Binding ElementName=MeterInstance, Path=AutoHandState}"
Style="{StaticResource MaterialDesignSwitchToggleButton}"
ToolTip="手自动" />
<TextBlock
Margin="3,3,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="CadetBlue"
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}" />
</StackPanel>
<TabControl Grid.Row="1" Grid.ColumnSpan="2">
<TabControl.Template>
<ControlTemplate TargetType="TabControl">
<Grid>
<ContentPresenter ContentSource="SelectedContent" />
</Grid>
</ControlTemplate>
</TabControl.Template>
<TabControl.Style>
<Style TargetType="TabControl">
<Setter Property="SelectedIndex" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=ToggleBtnAutoHand}" Value="True">
<Setter Property="SelectedIndex" Value="1" />
</DataTrigger>
</Style.Triggers>
</Style>
</TabControl.Style>
<TabItem>
<TextBlock
Margin="2,2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
xml:space="preserve"
FontSize="12"
FontWeight="Bold"
Foreground="#404040"
Text="{Binding ElementName=MeterInstance, Path=StepExeInfo}"
TextAlignment="Center" />
</TabItem>
<TabItem>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- MV -->
<StackPanel Margin="3,3,3,0">
<StackPanel.Resources />
<!--
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}"
Command="{Binding ElementName=MeterInstance, Path=AutoHandCommand}"
CommandParameter="{Binding ElementName=MeterInstance}"
把整个控件作为参数传递进去 Text="{Binding ElementName=MeterInstance, Path=HandValueMVParameter}"
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}" 用TabControl控制了不需要显示了
-->
<TextBox
x:Name="HandValueMV"
Width="42"
HorizontalContentAlignment="Center"
KeyDown="HandValueMV_KeyDown"
ToolTip="按【Enter】回车键才会发送生效">
<TextBox.Style>
<Style BasedOn="{StaticResource MaterialDesignTextBox}" TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Text" Value="{Binding ElementName=MeterInstance, Path=HandValueTempMVParameter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="Background" Value="LimeGreen" />
</Trigger>
<Trigger Property="IsFocused" Value="False">
<Setter Property="Text" Value="{Binding ElementName=MeterInstance, Path=HandValueMVParameter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBlock
Margin="0,2,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="CadetBlue"
Text="MV" />
</StackPanel>
<!-- SV -->
<StackPanel Grid.Column="1" Margin="3,3,3,0">
<StackPanel.Resources />
<!--
Text="{Binding ElementName=MeterInstance, Path=AutoStateMsg}"
Command="{Binding ElementName=MeterInstance, Path=AutoHandCommand}"
CommandParameter="{Binding ElementName=MeterInstance}"
把整个控件作为参数传递进去 Text="{Binding ElementName=MeterInstance, Path=HandValueSVParameter, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
-->
<TextBox
x:Name="HandValueSV"
Width="42"
HorizontalContentAlignment="Center"
KeyDown="HandValueSV_KeyDown"
ToolTip="按【Enter】回车键才会发送生效">
<TextBox.Style>
<Style BasedOn="{StaticResource MaterialDesignTextBox}" TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Text" Value="{Binding ElementName=MeterInstance, Path=HandValueTempSVParameter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="Background" Value="LimeGreen" />
</Trigger>
<Trigger Property="IsFocused" Value="False">
<Setter Property="Text" Value="{Binding ElementName=MeterInstance, Path=HandValueSVParameter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBlock
Margin="0,2,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="CadetBlue"
Text="SV" />
</StackPanel>
</Grid>
</TabItem>
</TabControl>
</Grid>
<Border
Grid.Row="2"
Margin="1,2,1,2"
Background="Gray"
CornerRadius="3">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="12"
Foreground="White"
Text="{Binding ElementName=MeterInstance, Path=MeterName}">
<TextBlock.ContextMenu>
<ContextMenu>
<!--
ContextMenu在WPF中是一个特殊元素它不在常规视觉树中而是在独立的窗口中
这导致ElementName绑定可能无法正常工作,没有使用Command处理所以用这个方式来获取
-->
<MenuItem Click="ExdMenuClick" Header="更多控制" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</Border>
</Grid>
</materialDesign:Card>
</UserControl>