Przeglądaj źródła

增加控件

样式分支
fyf 2 lat temu
rodzic
commit
66d63fdba5
7 zmienionych plików z 706 dodań i 8 usunięć
  1. +294
    -0
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml
  2. +359
    -0
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  3. +13
    -0
      BeDesignerSCADA/MainTest.xaml
  4. +30
    -0
      BeDesignerSCADA/MainTest.xaml.cs
  5. +2
    -1
      BeDesignerSCADA/MainWindow.xaml.cs
  6. +7
    -7
      BeDesignerSCADA/Themes/Styles.xaml
  7. +1
    -0
      WPFDemo/WPFDemo.csproj

+ 294
- 0
BeDesignerSCADA/Controls/MainCanvasPanel.xaml Wyświetl plik

@@ -0,0 +1,294 @@
<UserControl x:Class="BeDesignerSCADA.Controls.MainCanvasPanel"
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:BeDesignerSCADA.Controls"
xmlns:s="clr-namespace:BeDesignerSCADA.Converters"
xmlns:icon="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:avae="http://icsharpcode.net/sharpdevelop/avalonedit"
xmlns:ctl="clr-namespace:BeDesignerSCADA.Controls"
xmlns:mypro="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="900" d:DesignWidth="1400">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BeDesignerSCADA;component/Themes/Styles.xaml" />
<ResourceDictionary Source="/BPASmartClient.SCADAControl;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240"/>
<ColumnDefinition/>
<ColumnDefinition Width="350"/>
</Grid.ColumnDefinitions>
<!--左侧选择区域-->
<Grid Background="White" >
<Border BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Margin="4">
<ListBox x:Name="CtlList" Background="Transparent" ItemTemplate="{DynamicResource ToolBoxStyle}" BorderThickness="0" PreviewMouseMove="CtlList_PreviewMouseMove">
</ListBox>
</Border>
</Grid>



<!--中间控制区域-->
<DockPanel Grid.Column="1">
<!--按钮控制-->
<DockPanel LastChildFill="False" DockPanel.Dock="Top" Height="24" Margin="4 4 4 0">
<Button Margin="0" Width="24" Padding="0" Click="AglinLeftBtn_Click" ToolTip="左对齐">
<icon:PackIconModern Kind="AlignLeft"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="AglinRightBtn_Click" ToolTip="右对齐">
<icon:PackIconModern Kind="AlignRight"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="AglinCenterBtn_Click" ToolTip="中心对齐">
<icon:PackIconModern Kind="AlignCenter"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="AglinTopBtn_Click" ToolTip="上对齐">
<icon:PackIconModern Kind="BorderTop"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="AglinBottomBtn_Click" ToolTip="下对齐">
<icon:PackIconModern Kind="BorderBottom"/>
</Button>
<Button Margin="16 0 0 0" Width="24" Padding="0" Click="HorizontalLayoutBtn_Click" ToolTip="水平分布">
<icon:PackIconModern Kind="BorderHorizontal"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="VerticalLayoutBtn_Click" ToolTip="垂直分布">
<icon:PackIconModern Kind="BorderVertical"/>
</Button>

<ToggleButton IsChecked="{Binding UseAutoAlignment, ElementName=cav, Mode=TwoWay}" ToolTip="使用对齐网格" Margin="4 0 0 0" Width="24" Padding="0">
<icon:PackIconModern Kind="CellAlign"/>
</ToggleButton>

<Button Margin="16 0 0 0" Width="24" Padding="0" ToolTip="复制" Command="{Binding ElementName=cav, Path=CopySelectItemsCommand}">
<icon:PackIconModern Kind="PageCopy"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" ToolTip="粘贴" Command="{Binding ElementName=cav, Path=PasteSelectItemsCommand}">
<icon:PackIconModern Kind="ClipboardPaste"/>
</Button>
<Button Margin="4 0 0 0" Width="24" Padding="0" ToolTip="删除" Command="{Binding ElementName=cav, Path=DeleteSelectItemsCommand}">
<icon:PackIconModern Kind="Delete"/>
</Button>

<Button x:Name="RunBtn" Margin="16 0 0 0" Padding="0" Click="RunBtn_Click" Command="{Binding RunUiCommand}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Tag" Value="运行"/>
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal" Margin="8 0">
<icon:PackIconModern Kind="ControlPlay" VerticalAlignment="Center" Foreground="#28B60F" Width="8"/>
<TextBlock Text="运行" Margin="4 0" VerticalAlignment="Center"/>
</StackPanel>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsRunning}" Value="True">
<Setter Property="Tag" Value="停止"/>
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal" Margin="8 0">
<icon:PackIconModern Kind="ControlStop" VerticalAlignment="Center" Foreground="#B60F0F" Width="8"/>
<TextBlock Text="停止" Margin="4 0" VerticalAlignment="Center"/>
</StackPanel>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>

<Button x:Name="SaveBtn" Margin="16 0 0 0" Padding="0" Click="SaveBtn_Click">
<StackPanel Orientation="Horizontal" Margin="8 0">
<icon:PackIconModern Kind="Save" VerticalAlignment="Center" Width="12"/>
<TextBlock Text="保存" Margin="4 0" VerticalAlignment="Center"/>
</StackPanel>
</Button>

<Button x:Name="LoadBtn" Margin="4 0 0 0" Padding="0" Click="LoadBtn_Click">
<StackPanel Orientation="Horizontal" Margin="8 0">
<icon:PackIconModern Kind="DiskDownload" VerticalAlignment="Center" Width="14"/>
<TextBlock Text="加载" Margin="4 0" VerticalAlignment="Center"/>
</StackPanel>
</Button>

<Button x:Name="MNBtn" Margin="4 0 0 0" Padding="0" Click="MNBtn_Click">
<StackPanel Orientation="Horizontal" Margin="8 0">
<icon:PackIconModern Kind="MessageSend" VerticalAlignment="Center" Width="14"/>
<TextBlock Text="模拟消息" Margin="4 0" VerticalAlignment="Center"/>
</StackPanel>
</Button>

<ToggleButton x:Name="showCode" Click="showCode_Click" DockPanel.Dock="Right" Margin="4 0 0 0" Padding="4 0">
<icon:Material Kind="FileCode"/>
</ToggleButton>

<Slider DockPanel.Dock="Right" Width="100" Maximum="16" Minimum="1" Margin="4 0 0 0"
HorizontalContentAlignment="Center" Value="{Binding ElementName=cav,Path=GridPxiel}" ></Slider>
<TextBlock DockPanel.Dock="Right" Text="对齐:" VerticalAlignment="Center" Margin="16 0 0 0"/>

</DockPanel>

<!--中间画布-->
<Border BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Margin="4">
<Border.Background>
<ImageBrush ImageSource="/Images/bj.png" Stretch="UniformToFill"/>
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<ctl:CanvasPanel x:Name="cav" Visibility="{Binding CanvasPanelVisibility}" SelectedItem="{Binding CanSelectedItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AllowDrop="True" RenderTransformOrigin="0.5,0.5" ClipToBounds="True" UseLayoutRounding="True" Focusable="True" SnapsToDevicePixels="True">
<ctl:CanvasPanel.Background>
<VisualBrush TileMode="Tile" Viewport="0,0,20,20" ViewportUnits="Absolute">
<VisualBrush.Visual>
<Rectangle Width="20" Height="20" StrokeDashArray="4,2" StrokeThickness="0.5" Stroke="#CBCBCB">
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding UseAutoAlignment, RelativeSource={RelativeSource AncestorType={x:Type ctl:CanvasPanel}, Mode=FindAncestor}}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding UseAutoAlignment, RelativeSource={RelativeSource AncestorType={x:Type ctl:CanvasPanel}, Mode=FindAncestor}}" Value="False">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</VisualBrush.Visual>
</VisualBrush>
</ctl:CanvasPanel.Background>

<ctl:CanvasPanel.RenderTransform>
<TransformGroup>
<TranslateTransform x:Name="CanvasTranslate"/>
</TransformGroup>
</ctl:CanvasPanel.RenderTransform>
</ctl:CanvasPanel>

<ctl:RunCanvas x:Name="runCanvas" Visibility="{Binding RunCanvasVisibility}" />

<avae:TextEditor x:Name="codeEditor" ShowLineNumbers="True" Padding="4" WordWrap="True" IsReadOnly="True" SyntaxHighlighting="XML" BorderThickness="1 0 0 0" BorderBrush="{StaticResource ControlBorderBrush}" Grid.Column="1" Width="480" Visibility="{Binding ElementName=showCode, Path=IsChecked, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"/>
</Grid>
</Border>
</DockPanel>

<GridSplitter HorizontalAlignment="Right" Grid.Column="1" VerticalAlignment="Stretch" Width="5" Background="Transparent"/>

<!--右侧属性栏-->
<Grid Grid.Column="2">
<TabControl SelectedIndex="0">
<TabItem Header="控制协议">
<mypro:PropertyGrid x:Name="kzxy" SelectedObject="{Binding PropeObject}"
Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True"
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False"
CategoryGroupHeaderTemplate="{DynamicResource Category}">
<mypro:PropertyGrid.EditorDefinitions>
<!--EditorTemplateDefinition可添加多个-->
<!--要修改编辑模板的属性的名称-->
<mypro:EditorTemplateDefinition TargetProperties="点击事件,值改变事件,定时触发,勾选事件,取消勾选事件" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<Grid>
<!-- Command生效: DataTemplate的DataContext指代不明确,需要改为父类的DataContext。 参数Value表示原对象-->
<!--Command="{Binding Path=DataContext.PropeSetCommand ,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=xctk:PropertyGrid}}"-->
<!--DataContext="{Binding DataContext, ElementName=window}" Command="{Binding PropeSetCommand}" CommandParameter="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" x:Name="key"/>
<ColumnDefinition Width="35"/>
</Grid.ColumnDefinitions>
<TextBox Width="{Binding Width, ElementName=key}" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"></TextBox>
<ToggleButton Grid.Column="1" Height="25" Content="编辑" Width="30" HorizontalAlignment="Left" Click="ToggleButton_Click"></ToggleButton>
</Grid>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="代码过滤脚本" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBox Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" TextWrapping="Wrap"></TextBox>
</ScrollViewer>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="设备解析变量" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<Grid>
<ComboBox Grid.Column="1" Height="25" Width="{Binding Width, ElementName=com}" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window},Path=DataContext.DevValueList}"
></ComboBox>
</Grid>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="设备名称" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<Grid>
<ComboBox Grid.Column="1" Height="25" Width="{Binding Width, ElementName=com}" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window},Path=DataContext.DevNameList}"
></ComboBox>
</Grid>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="文本,文本1,标题,变量,勾选状态" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" x:Name="key"/>
<ColumnDefinition Width="*" x:Name="Text"/>
</Grid.ColumnDefinitions>
<TextBlock>绑定:</TextBlock>
<ComboBox x:Name="namebox" DropDownOpened="namebox_DropDownOpened" Grid.Column="1" Height="25" IsTextSearchEnabled="True" IsEditable="True" Tag="{Binding Text, ElementName=valuebox}" Width="{Binding Width, ElementName=key}" TextBoxBase.TextChanged="ComboBoxName_TextChanged"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window},Path=DataContext.DevNameList}">
</ComboBox>
<ComboBox x:Name="valuebox" DropDownOpened="valuebox_DropDownOpened" Grid.Column="2" Height="25" IsTextSearchEnabled="True" IsEditable="True" Tag="{Binding Text, ElementName=namebox}" Width="{Binding Width, ElementName=Text}" TextBoxBase.TextChanged="ComboBoxValue_TextChanged"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window},Path=DataContext.DevValueList}"/>
</Grid>
<TextBox Grid.Row="2" x:Name="wenben" Width="{Binding Width, ElementName=Text}" Padding="5" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"></TextBox>

</Grid>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>
</mypro:PropertyGrid.EditorDefinitions>
</mypro:PropertyGrid>
</TabItem>
<TabItem Header="控件样式">
<mypro:PropertyGrid x:Name="dsdsdsd"
Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True"
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False"
CategoryGroupHeaderTemplate="{DynamicResource Category}" SelectedObject="{Binding SelectedItem,ElementName=cav,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
</TabItem>
</TabControl>
</Grid>
</Grid>
</UserControl>

+ 359
- 0
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs Wyświetl plik

@@ -0,0 +1,359 @@
using BeDesignerSCADA.ViewModel;
using BeDesignerSCADA.ViewModel;
using BPASmart.Model;
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.MessageName;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BeDesignerSCADA.Controls
{
/// <summary>
/// MainCanvasPanel.xaml 的交互逻辑
/// </summary>
public partial class MainCanvasPanel : System.Windows.Controls.UserControl
{
/// <summary>
/// 布局文件路径
/// </summary>
public string Path=string.Empty;
MainViewModel viewModel = new MainViewModel();
public MainCanvasPanel(string _Path)
{
InitializeComponent();
Path= _Path;
this.DataContext = viewModel;
viewModel.Loaded(cav, runCanvas);
//控件加载
Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly();
var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name);
CtlList.ItemsSource = controls;
//读取文件
FileRead(_Path);
}
public MainCanvasPanel()
{
InitializeComponent();
this.DataContext = viewModel;
viewModel.Loaded(cav, runCanvas);
//控件加载
Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly();
var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name);
CtlList.ItemsSource = controls;
}

#region 位置调整
/// <summary>
/// 左对齐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AglinLeftBtn_Click(object sender, RoutedEventArgs e)
{
cav.AlignLeft();
}
/// <summary>
/// 底部对齐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AglinBottomBtn_Click(object sender, RoutedEventArgs e)
{
cav.AlignBottom();
}
/// <summary>
/// 顶部对齐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AglinTopBtn_Click(object sender, RoutedEventArgs e)
{
cav.AlignTop();
}
/// <summary>
/// 右对齐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AglinRightBtn_Click(object sender, RoutedEventArgs e)
{
cav.AlignRight();
}
/// <summary>
/// 居中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AglinCenterBtn_Click(object sender, RoutedEventArgs e)
{
cav.AlignCenter();
}
/// <summary>
/// 垂直分布
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void VerticalLayoutBtn_Click(object sender, RoutedEventArgs e)
{
cav.VertialLayout();
}
/// <summary>
/// 水平分布
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void HorizontalLayoutBtn_Click(object sender, RoutedEventArgs e)
{
cav.HorizontalLayout();
}
#endregion

#region 其他事件操作
/// <summary>
/// 运行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RunBtn_Click(object sender, RoutedEventArgs e)
{
if (sender is System.Windows.Controls.Button btn)
{
if (btn.Tag.ToString() == "运行")
{
cav.ClearSelection();
runCanvas.Run(cav.Generator());
}
else if (btn.Tag.ToString() == "停止")
{
runCanvas.Destory();
}
}
}
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadBtn_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "布局文件|*.lay";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
cav.Load(ofd.FileName);
}

DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250)));
da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da);

DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250)));
daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
cav.BeginAnimation(OpacityProperty, daop);
}
/// <summary>
/// 读取文件
/// </summary>
/// <param name="path"></param>
public void FileRead(string path)
{
try
{
if (File.Exists(path))
{
cav.Load(path);


DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250)));
da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da);

DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250)));
daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
cav.BeginAnimation(OpacityProperty, daop);
}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 保存文件
/// </summary>
public void FileSave()
{
SaveBtn_Click(null, null);
}
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
string str = cav.Save();
File.WriteAllText(Path, str, Encoding.Unicode);
}
/// <summary>
/// 模拟消息发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MNBtn_Click(object sender, RoutedEventArgs e)
{

}
#endregion

#region 左侧控件栏移动
/// <summary>
/// 移动到右侧
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CtlList_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (CtlList.SelectedItem != null && e.LeftButton == MouseButtonState.Pressed)
{
DragDrop.DoDragDrop(CtlList, CtlList.SelectedItem, System.Windows.DragDropEffects.Copy);
codeEditor.Text = cav.Save();
}
}
/// <summary>
/// 显示代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void showCode_Click(object sender, RoutedEventArgs e)
{
codeEditor.Text = cav.Save();
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (sender is ToggleButton)
{
ToggleButton toggle = (ToggleButton)sender;
Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
if (propertyGridCommand != null)
{
viewModel.Edit(propertyGridCommand);
}
}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 变量选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxValue_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (sender is System.Windows.Controls.ComboBox)
{
System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {toggle.Tag}.{toggle.Text}" + "}";
}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 变量下拉框打开事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void valuebox_DropDownOpened(object sender, EventArgs e)
{
try
{
viewModel.DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>();
if (sender is System.Windows.Controls.ComboBox)
{
System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
if (toggle.Tag == null) return;
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(toggle.Tag.ToString()))
{
Class_DataBus.GetInstance().Dic_DeviceData[toggle.Tag.ToString()].Keys?.ToList().ForEach(key => { viewModel.DevValueList.Add(key); });
}
}
}
catch (Exception ex)
{

}

}
/// <summary>
/// 设备名称选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxName_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (sender is System.Windows.Controls.ComboBox)
{
System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {toggle.Text}.{toggle.Tag}" + "}";
else if (!string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {toggle.Text}." + "}";

}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 设备名称下拉框打开事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void namebox_DropDownOpened(object sender, EventArgs e)
{
viewModel.DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { viewModel.DevNameList.Add(key); });
}
#endregion
}
}

+ 13
- 0
BeDesignerSCADA/MainTest.xaml Wyświetl plik

@@ -0,0 +1,13 @@
<Window x:Class="BeDesignerSCADA.MainTest"
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:local="clr-namespace:BeDesignerSCADA"
xmlns:k="clr-namespace:BeDesignerSCADA.Controls"
mc:Ignorable="d"
Title="MainTest" Height="450" Width="800">
<Grid x:Name="main">
</Grid>
</Window>

+ 30
- 0
BeDesignerSCADA/MainTest.xaml.cs Wyświetl plik

@@ -0,0 +1,30 @@
using BeDesignerSCADA.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BeDesignerSCADA
{
/// <summary>
/// MainTest.xaml 的交互逻辑
/// </summary>
public partial class MainTest : Window
{
public MainTest()
{
InitializeComponent();
MainCanvasPanel mainCanvas=new MainCanvasPanel(@"D:\fengyoufu\代码\Code\C#项目\新上位机代码\BPASmartClient.MinimalistUI\bin\Debug\net6.0-windows\LayoutFile\物料仓管理.lay");
main.Children.Add(mainCanvas);
}
}
}

+ 2
- 1
BeDesignerSCADA/MainWindow.xaml.cs Wyświetl plik

@@ -33,6 +33,7 @@ namespace BeDesignerSCADA
/// </summary>
public partial class MainWindow : Window
{

MainViewModel viewModel=new MainViewModel();
public MainWindow()
{
@@ -41,7 +42,7 @@ namespace BeDesignerSCADA
viewModel.Loaded(cav, runCanvas);
//控件加载
Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly();
var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null);
var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o=>o.Name);
CtlList.ItemsSource = controls;
}



+ 7
- 7
BeDesignerSCADA/Themes/Styles.xaml Wyświetl plik

@@ -235,15 +235,15 @@
<Setter Property="Text" TargetName="txt" Value="物料仓"/>
</DataTrigger>
<DataTrigger Binding="{Binding Name}" Value="NewConveyorBelt">
<Setter Property="Kind" TargetName="icon" Value="ArrowLeftRightBoldOutline"/>
<Setter Property="Kind" TargetName="icon" Value="Attachment"/>
<Setter Property="Text" TargetName="txt" Value="滚动线"/>
</DataTrigger>
<DataTrigger Binding="{Binding Name}" Value="TheDataGrid">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="BorderAll"/>
<Setter Property="Text" TargetName="txt" Value="表格"/>
</DataTrigger>
<DataTrigger Binding="{Binding Name}" Value="TheListBox">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="ViewHeadline"/>
<Setter Property="Text" TargetName="txt" Value="列表控件"/>
</DataTrigger>

@@ -258,22 +258,22 @@
</DataTrigger>

<DataTrigger Binding="{Binding Name}" Value="TheProgressBar">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="Texture"/>
<Setter Property="Text" TargetName="txt" Value="进度条正常"/>
</DataTrigger>

<DataTrigger Binding="{Binding Name}" Value="TheRedProgressBar">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="CircleSlice5"/>
<Setter Property="Text" TargetName="txt" Value="进度条圆形红"/>
</DataTrigger>

<DataTrigger Binding="{Binding Name}" Value="TheBlueProgressBar">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="CircleSlice5"/>
<Setter Property="Text" TargetName="txt" Value="进度条圆形蓝"/>
</DataTrigger>

<DataTrigger Binding="{Binding Name}" Value="TheGreenProgressBar">
<Setter Property="Kind" TargetName="icon" Value="LineScan"/>
<Setter Property="Kind" TargetName="icon" Value="CircleSlice5"/>
<Setter Property="Text" TargetName="txt" Value="进度条圆形绿"/>
</DataTrigger>



+ 1
- 0
WPFDemo/WPFDemo.csproj Wyświetl plik

@@ -20,6 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BeDesignerSCADA\BeDesignerSCADA.csproj" />
<ProjectReference Include="..\BPASmartClient.CustomResource\BPASmartClient.CustomResource.csproj" />
</ItemGroup>



Ładowanie…
Anuluj
Zapisz