1、工控温度计组件效果演示
工控上位机温度计组件设计与开发
2、画温度计边框
<Rectangle StrokeThickness="7" RadiusX="40" RadiusY="15" Fill="White" />
<Rectangle StrokeThickness="7" RadiusX="40" RadiusY="15">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="0" Direction="0" BlurRadius="7" />
</Rectangle.Effect>
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,1" EndPoint="1,0">
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="40" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="Black" />
<GradientStop Color="White" Offset="0.7" />
</LinearGradientBrush>
</Rectangle.Stroke>
</Rectangle>
3、画水平柱
<TextBlock Text="℃" HorizontalAlignment="Center" VerticalAlignment="Top"
FontWeight="Bold" FontSize="20" Margin="0, 20" Foreground="#555"/>
<!--刻度布局和初始化留到代码逻辑实现-->
<Canvas Name="MainCanvas" Width="75" Margin="0,70" />
<Border Width="10" RenderTransformOrigin="0.5,0.5" CornerRadius="5" Margin="0,50">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Direction="0" Color="White" />
</Border.Effect>
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="lightGray" Offset="0" />
<GradientStop Color="White" Offset="0.4" />
<GradientStop Color="lightGray" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border Height="75" VerticalAlignment="Bottom" Name="BorValue">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#CD3333" />
<GradientStop Color="#FFC0CB" Offset="0.4" />
<GradientStop Color="#CD3333" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
</Border>
4、画水银珠
<Border Height="25" Width="25" CornerRadius="15" VerticalAlignment="Bottom"
Margin="0 0 0 30">
<Border.Effect>
<DropShadowEffect Direction="0" ShadowDepth="0" />
</Border.Effect>
<Border.Background>
<RadialGradientBrush Center="0.3,0.2" GradientOrigin="0.4,0.4">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="#CD3333" Offset="1" />
</RadialGradientBrush>
</Border.Background>
</Border>
5、后台温度计初始化刻度
private void RefreshComponet()
{
var h = this.MainCanvas.ActualHeight;
if (h == 0) return;
double w = 75;
double stepCount = Maxmum - Minmum;
double step = h / (Maxmum - Minmum);
this.MainCanvas.Children.Clear();
for (int i = 0; i <= stepCount; i++)
{
Line line = new Line();
line.Y1 = i * step;
line.Y2 = i * step;
line.Stroke = Brushes.Black;
line.StrokeThickness = 1;
this.MainCanvas.Children.Add