Files
CapMachine/CapMachine.Shared/Controls/Meter.xaml
2025-03-26 19:52:04 +08:00

218 lines
10 KiB
XML

<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*" />
<RowDefinition Height="3*" />
<RowDefinition Height="1.5*" />
</Grid.RowDefinitions>
<Border
Margin="1,3,1,0"
Background="#404040"
CornerRadius="3" />
<StackPanel Margin="1,3,1,0">
<DockPanel Margin="1,3">
<TextBlock
Margin="1,0,1,0"
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="14"
Foreground="White"
Text="PV" />
<TextBlock
Margin="0,0,0,0"
VerticalAlignment="Center"
FontSize="13"
Foreground="White"
Text="{Binding ElementName=MeterInstance, Path=PVValue}" />
<TextBlock
Margin="0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
DockPanel.Dock="Right"
FontSize="10"
Foreground="White"
Text="{Binding ElementName=MeterInstance, Path=Unit}" />
</DockPanel>
<DockPanel Margin="1,-3,2,0">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="16"
FontStyle="Italic"
Foreground="Gold"
Text="SV" />
<TextBlock
Margin="5,0,5,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>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel
Grid.ColumnSpan="2"
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>
<StackPanel
Grid.Row="1"
Grid.Column="0"
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}"
-->
<TextBox
x:Name="HandValueMV"
Width="42"
HorizontalContentAlignment="Center"
KeyDown="HandValueMV_KeyDown"
ToolTip="按【Enter】回车键才会发送生效"
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}">
<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"
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}" />
</StackPanel>
<StackPanel
Grid.Row="1"
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】回车键才会发送生效"
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}">
<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"
Visibility="{Binding ElementName=MeterInstance, Path=IsHandValueShow}" />
</StackPanel>
</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}" />
</Border>
</Grid>
</materialDesign:Card>
</UserControl>