2021-09-03 WPF上位机通用框架平台实战-Dashboard

Posted 微软MVP Eleven

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-09-03 WPF上位机通用框架平台实战-Dashboard相关的知识,希望对你有一定的参考价值。

一:Dashboard窗口布局和功能实现

<UserControl x:Class="Zhaoxi.HostComputer.Views.MonitorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Zhaoxi.HostComputer.Views"
             xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             mc:Ignorable="d" Foreground="#444" UseLayoutRounding="True" TextOptions.TextRenderingMode="ClearType"
             d:DesignHeight="650" d:DesignWidth="1000">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Zhaoxi.HostComputer;component/Assets/Styles/DataGridStyle.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/Zhaoxi.HostComputer;component/Assets/Styles/ScrollViewerStyle.xaml"/>

                <ResourceDictionary>
                    <Style TargetType="RadioButton" x:Key="TimeRangeButtonStyle">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="RadioButton">
                                    <TextBlock Text="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="11"/>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsChecked" Value="True">
                                            <Setter Property="Foreground" Value="#FF3269DE"/>
                                            <Setter Property="FontWeight" Value="Bold"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid Margin="30,20">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="1.5*"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="#EEE" BorderThickness="0,0,1,0"/>
            <Border BorderBrush="#EEE" BorderThickness="0,0,1,0" Grid.Column="1"/>
            <!--基本信息-->
            <Grid Margin="0,0,10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Text="设备运行工况" FontWeight="Bold" Foreground="#555" VerticalAlignment="Center" Margin="5,0"/>
                <UniformGrid Columns="3" Grid.Row="1">
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="当前状态" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="运行" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="周运行时长" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="80h" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="周关机时长" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="50h" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="周待机时长" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="50h" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="周故障时长" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="2h" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                    <Border Background="White" CornerRadius="5" Margin="5">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                        </Border.Effect>
                        <Grid VerticalAlignment="Center" Margin="10,0">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="健康状态" FontSize="10" Foreground="#999"/>
                            <TextBlock Text="良好" Grid.Row="1" FontSize="14" Margin="0,3"/>
                        </Grid>
                    </Border>
                </UniformGrid>

                <TextBlock Text="设备基本信息" Grid.Row="3" FontWeight="Bold" Foreground="#555" VerticalAlignment="Center" Margin="5,0"/>
                <UniformGrid Grid.Row="4" Columns="3">
                    <StackPanel Margin="5">
                        <TextBlock Text="1.44m" FontSize="16"/>
                        <TextBlock Text="最大工作范围" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="20kg" FontSize="16"/>
                        <TextBlock Text="有效载荷" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="6J" FontSize="16"/>
                        <TextBlock Text="有效轴数" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="0.001cm" FontSize="16"/>
                        <TextBlock Text="重复定位精确度" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="2500w" FontSize="16"/>
                        <TextBlock Text="额定功率" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="5kg" FontSize="16"/>
                        <TextBlock Text="承重能力" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="2.1m/s" FontSize="16"/>
                        <TextBlock Text="J6轴最大速度" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="200-600v" FontSize="16"/>
                        <TextBlock Text="电源电压" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                    <StackPanel Margin="5">
                        <TextBlock Text="225kg" FontSize="16"/>
                        <TextBlock Text="净重" FontSize="10" Foreground="#666" Margin="0,3"/>
                    </StackPanel>
                </UniformGrid>
            </Grid>

            <!--参数分析-->
            <Grid Margin="10,0" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Text="参数分析" FontWeight="Bold" Foreground="#555" VerticalAlignment="Center" Margin="5,0"/>
                <Border Background="White" Grid.Row="1" CornerRadius="5" Margin="5">
                    <Border.Effect>
                        <DropShadowEffect ShadowDepth="0" BlurRadius="3" Opacity="0.1"/>
                    </Border.Effect>
                </Border>
                <UniformGrid Columns="2" Grid.Row="1">
                    <Grid Margin="20">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="[电压]" VerticalAlignment="Top"/>
                        <lvc:CartesianChart Grid.Row="1">
                            <lvc:CartesianChart.Series>
                                <lvc:LineSeries Stroke="#FF7261" PointGeometrySize="0" Values="156,600,70,760,320,540,880,340,500">
                                    <lvc:LineSeries.Fill>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="#FFE3E0" Offset="0"/>
                                            <GradientStop Color="White" Offset="1"/>
                                        </LinearGradientBrush>
                                    </lvc:LineSeries.Fill>
                                </lvc:LineSeries>
                            </lvc:CartesianChart.Series>
                            <lvc:CartesianChart.AxisX>
                                <lvc:Axis ShowLabels="True" Labels="1:00,2:00,3:00,4:00,5:00,6:00,7:00,8:00,9:00" 
                                          LabelsRotation="0" FontSize="8">
                                    <lvc:Axis.Separator>
                                        <lvc:Separator Step="1" StrokeThickness="0"/>
                                    </lvc:Axis.Separator>
                                </lvc:Axis>
                            </lvc:CartesianChart.AxisX>
                            <lvc:CartesianChart.AxisY>
                                <lvc:Axis MinValue="0" ShowLabels="True" FontSize="8">
                                    <lvc:Axis.Separator>
                                        <lvc:Separator Step="200"/>
                                    </lvc:Axis.Separator>
                                </lvc:Axis>
                            </lvc:CartesianChart.AxisY>
                        </lvc:CartesianChart>
                    </Grid>
                    <Grid Margin="20">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="[电流]" VerticalAlignment="Top"/>
                        <lvc:CartesianChart Grid.Row="1">
                            <lvc:CartesianChart.Series>
                                <lvc:LineSeries Stroke="#FECC71"
                                                    PointGeometrySize="0" Values="156,600,70,760,320,540,880,340,500">
                                    <lvc:LineSeries.Fill>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="#FFF2DE" Offset="0"/>
                                            <GradientStop Color="White" Offset="1"/>
                                        </LinearGradientBrush>
                                    </lvc:LineSeries.Fill>
                                </lvc:LineSeries>
                            </lvc:CartesianChart.Series>
                            <lvc:CartesianChart.AxisX>
                                <lvc:Axis ShowLabels&#

以上是关于2021-09-03 WPF上位机通用框架平台实战-Dashboard的主要内容,如果未能解决你的问题,请参考以下文章

2021-09-04 WPF上位机通用框架平台实战-设备编辑

2021-09-04 WPF上位机通用框架平台实战-全局监控对象

2021-09-04 WPF上位机通用框架平台实战-Device

2021-09-02 WPF上位机通用框架平台实战-登录窗口

2021-09-04 WPF上位机通用框架平台实战-主窗口

有小伙伴问:上位机用QT还是winform/wpf好?