[UI.Client]

新增ModuleStatusIndicator控件。
This commit is contained in:
SL 2023-08-15 12:39:17 +08:00
parent 5aba7fa7de
commit 96630d9c96
3 changed files with 305 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<UserControl x:Class="MECF.Framework.UI.Client.Ctrlib.Controls.ModuleStatusIndicator"
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:MECF.Framework.UI.Client.Ctrlib.Controls"
xmlns:converters="clr-namespace:MECF.Framework.UI.Core.Converters;assembly=MECF.Framework.UI.Core"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<converters:BoolReverseConverter x:Key="BoolReverseConverter"/>
<local:ModuleIsOnlineToBgColorConverter x:Key="IsOnlineToBdrColor"/>
<local:ModuleStatusToBackgroundColorConverter x:Key="StatusToBgColor"/>
</UserControl.Resources>
<DockPanel DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Mode=OneTime}">
<Label
DockPanel.Dock="Left"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Width="{Binding CaptionWidth}"
BorderBrush="{Binding IsOnline, Converter={StaticResource IsOnlineToBdrColor}}"
Content="{Binding Caption}"
ToolTip="{Binding ModuleDescription}"
Style="{DynamicResource TopLable_LeftTop}" HorizontalAlignment="Left">
<Label.ContextMenu>
<ContextMenu>
<MenuItem
x:Name="CmSetOnline"
Header="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Content}"
HeaderStringFormat="Set {0} Online"
IsEnabled="{Binding IsOnline, Converter={StaticResource BoolReverseConverter}}"
Click="CmSetOnline_OnClick"/>
<MenuItem
x:Name="CmSetOffline"
Header="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Content}"
HeaderStringFormat="Set {0} Offline"
IsEnabled="{Binding IsOnline}"
Click="CmSetOffline_OnClick"/>
</ContextMenu>
</Label.ContextMenu>
</Label>
<TextBox
DockPanel.Dock="Left"
VerticalContentAlignment="Center"
Background="{Binding Status, Converter={StaticResource StatusToBgColor}}"
Style="{StaticResource TextBox_Top}"
Text="{Binding Status, Mode=OneWay}"
IsReadOnly="True"
TextWrapping="Wrap" Margin="0,2,2,2" />
</DockPanel>
</UserControl>

View File

@ -0,0 +1,246 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
namespace MECF.Framework.UI.Client.Ctrlib.Controls
{
/// <summary>
/// Interaction logic for ModuleStatusIndicator.xaml
/// </summary>
public partial class ModuleStatusIndicator : UserControl
{
public ModuleStatusIndicator()
{
InitializeComponent();
}
#region Dependency Properties
#region DP - Caption
public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register(
nameof(Caption), typeof(string), typeof(ModuleStatusIndicator), new PropertyMetadata(default(string)));
/// <summary>
/// 设置或返回标题
/// </summary>
public string Caption
{
get => (string)GetValue(CaptionProperty);
set => SetValue(CaptionProperty, value);
}
#endregion
#region DP - Caption Width
public static readonly DependencyProperty CaptionWidthProperty = DependencyProperty.Register(
nameof(CaptionWidth), typeof(double), typeof(ModuleStatusIndicator), new PropertyMetadata(100.0d));
public double CaptionWidth
{
get => (double)GetValue(CaptionWidthProperty);
set => SetValue(CaptionWidthProperty, value);
}
#endregion
#region DP - Status
public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(
nameof(Status), typeof(string), typeof(ModuleStatusIndicator), new PropertyMetadata(default(string)));
public string Status
{
get => (string)GetValue(StatusProperty);
set => SetValue(StatusProperty, value);
}
#endregion
#region DP - IsOnline
public static readonly DependencyProperty IsOnlineProperty = DependencyProperty.Register(
nameof(IsOnline), typeof(bool), typeof(ModuleStatusIndicator), new PropertyMetadata(default(bool)));
public bool IsOnline
{
get => (bool)GetValue(IsOnlineProperty);
set => SetValue(IsOnlineProperty, value);
}
#endregion
#region DP - ModuleName
public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
nameof(ModuleName), typeof(string), typeof(ModuleStatusIndicator), new PropertyMetadata(default(string)));
public string ModuleName
{
get => (string)GetValue(ModuleNameProperty);
set => SetValue(ModuleNameProperty, value);
}
#endregion
#region DP - Module Description
public static readonly DependencyProperty ModuleDescriptionProperty = DependencyProperty.Register(
nameof(ModuleDescription), typeof(string), typeof(ModuleStatusIndicator), new PropertyMetadata(default(string)));
public string ModuleDescription
{
get => (string)GetValue(ModuleDescriptionProperty);
set => SetValue(ModuleDescriptionProperty, value);
}
#endregion
#region DP - IsInterlockBypassed
public static readonly DependencyProperty IsInterlockBypassedProperty = DependencyProperty.Register(
nameof(IsInterlockBypassed), typeof(bool), typeof(ModuleStatusIndicator), new PropertyMetadata(default(bool)));
public bool IsInterlockBypassed
{
get => (bool)GetValue(IsInterlockBypassedProperty);
set => SetValue(IsInterlockBypassedProperty, value);
}
#endregion
#region DP - SetOnline Command
public static readonly DependencyProperty SetOnlineCommandProperty = DependencyProperty.Register(
nameof(SetOnlineCommand), typeof(ICommand), typeof(ModuleStatusIndicator), new PropertyMetadata(default(ICommand)));
public ICommand SetOnlineCommand
{
get => (ICommand)GetValue(SetOnlineCommandProperty);
set => SetValue(SetOnlineCommandProperty, value);
}
#endregion
#region DP - SetOffline Command
public static readonly DependencyProperty SetOfflineCommandProperty = DependencyProperty.Register(
nameof(SetOfflineCommand), typeof(ICommand), typeof(ModuleStatusIndicator), new PropertyMetadata(default(ICommand)));
public ICommand SetOfflineCommand
{
get => (ICommand)GetValue(SetOfflineCommandProperty);
set => SetValue(SetOfflineCommandProperty, value);
}
#endregion
#endregion
#region Event Handler
private void CmSetOnline_OnClick(object sender, RoutedEventArgs e)
{
RaiseEvent(new RoutedEventArgs(SetOnlineEvent));
}
private void CmSetOffline_OnClick(object sender, RoutedEventArgs e)
{
RaiseEvent(new RoutedEventArgs(SetOfflineEvent));
}
#endregion
#region Routed Events
public static readonly RoutedEvent SetOnlineEvent = EventManager.RegisterRoutedEvent(nameof(SetOnline), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UserControl));
public event RoutedEventHandler SetOnline
{
add => AddHandler(SetOnlineEvent, value);
remove => RemoveHandler(SetOnlineEvent, value);
}
public static readonly RoutedEvent SetOfflineEvent = EventManager.RegisterRoutedEvent(nameof(SetOffline), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UserControl));
public event RoutedEventHandler SetOffline
{
add => AddHandler(SetOfflineEvent, value);
remove => RemoveHandler(SetOfflineEvent, value);
}
#endregion
}
internal class ModuleIsOnlineToBgColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool isOnline)
{
if (isOnline)
return new SolidColorBrush(Colors.LawnGreen);
else
{
return new SolidColorBrush(Colors.Gray);
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
internal class ModuleStatusToBackgroundColorConverter : IValueConverter
{
public static Color GetStatusBackground(string status)
{
if (status != null)
{
status = status.Trim().ToLower();
}
switch (status)
{
case "error":
return Colors.OrangeRed;
case "processidle":
case "vacidle":
case "idle":
case "manual":
return Colors.White;
case "notconnect":
case "init":
return Colors.Yellow;
case "offline":
case "notinstall":
return Colors.Gray;
default:
return Colors.LawnGreen;
}
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string status)
{
return new SolidColorBrush(GetStatusBackground(status));
}
return Colors.BlanchedAlmond;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -249,6 +249,9 @@
<Compile Include="Ctrlib\Controls\HeaterResPresenter.xaml.cs">
<DependentUpon>HeaterResPresenter.xaml</DependentUpon>
</Compile>
<Compile Include="Ctrlib\Controls\ModuleStatusIndicator.xaml.cs">
<DependentUpon>ModuleStatusIndicator.xaml</DependentUpon>
</Compile>
<Compile Include="Ctrlib\Controls\PanelLocker.xaml.cs">
<DependentUpon>PanelLocker.xaml</DependentUpon>
</Compile>
@ -898,6 +901,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Ctrlib\Controls\ModuleStatusIndicator.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="RecipeEditorLib\DGExtension\DataGridRecipe.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>