给变量添加Mqtt服务器的功能
This commit is contained in:
21
Views/Dialogs/MqttSelectionDialog.xaml
Normal file
21
Views/Dialogs/MqttSelectionDialog.xaml
Normal file
@@ -0,0 +1,21 @@
|
||||
<controls:ContentDialog x:Class="PMSWPF.Views.Dialogs.MqttSelectionDialog"
|
||||
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels.Dialogs"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance vm:MqttSelectionDialogViewModel}"
|
||||
Title="选择MQTT服务器"
|
||||
PrimaryButtonText="确定"
|
||||
SecondaryButtonText="取消"
|
||||
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
|
||||
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding Mqtts}"
|
||||
SelectedItem="{Binding SelectedMqtt}"
|
||||
DisplayMemberPath="Name" />
|
||||
</Grid>
|
||||
</controls:ContentDialog>
|
||||
@@ -191,6 +191,12 @@
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="添加MQTT服务器"
|
||||
Click="AddMqttServerToVariables_Click">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Add}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.RowStyle>
|
||||
|
||||
@@ -145,4 +145,27 @@ public partial class VariableTableView : UserControl
|
||||
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void AddMqttServerToVariables_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_viewModel = (VariableTableViewModel)this.DataContext;
|
||||
var selectedVariables = BasicGridView.SelectedItems.Cast<VariableData>().ToList();
|
||||
if (selectedVariables.Any())
|
||||
{
|
||||
await _viewModel.AddMqttServerToVariables(selectedVariables);
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationHelper.ShowMessage("请选择要添加MQTT服务器的变量", NotificationType.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string msg = "添加MQTT服务器时发生了错误:";
|
||||
Logger.Error(msg + ex);
|
||||
NotificationHelper.ShowMessage(msg + ex.Message, NotificationType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user