Browse Source

更新图片

样式分支
fyf 2 years ago
parent
commit
bdf30b924d
4 changed files with 71 additions and 10 deletions
  1. +32
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs
  2. +2
    -2
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml
  3. +1
    -0
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  4. +36
    -7
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 32
- 1
BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs View File

@@ -2,6 +2,7 @@
using BPASmartClient.SCADAControl;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -32,7 +33,27 @@ namespace BPASmartClient.SCADAControl.CustomerControls
Width = 80;
Height = 80;
}

/// <summary>
/// 启动路径
/// </summary>
public string ImageStartPath
{
get { return (string)GetValue(StartPathProperty); }
set { SetValue(StartPathProperty, value); }
}
public static readonly DependencyProperty StartPathProperty =
DependencyProperty.Register("ImageStartPath", typeof(string), typeof(TheImage), new PropertyMetadata(string.Empty,new PropertyChangedCallback(OnPropertyChanged)));
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as TheImage)?.Refresh();
}
private void Refresh()
{
if (!string.IsNullOrEmpty(ImageStartPath) && File.Exists(ImageStartPath))
{
Source = new BitmapImage(new Uri(ImageStartPath));
}
}
public string ControlType => "控件";

private bool isExecuteState;
@@ -51,6 +72,16 @@ namespace BPASmartClient.SCADAControl.CustomerControls

public void Register()
{
if (!string.IsNullOrEmpty(ImageStartPath))
{
string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Images\\{System.IO.Path.GetFileName(ImageStartPath)}";
if (File.Exists(path))
{
ImageStartPath = path;
Source = new BitmapImage(new Uri(ImageStartPath));
}
}

}
}


+ 2
- 2
BeDesignerSCADA/Controls/MainCanvasPanel.xaml View File

@@ -231,7 +231,7 @@
<mypro:PropertyDefinition DisplayName="宽度" Category="基本属性" DisplayOrder="3" Name="Width"/>
<mypro:PropertyDefinition DisplayName="高度" Category="基本属性" DisplayOrder="3" Name="Height"/>
<mypro:PropertyDefinition DisplayName="勾选状态" Category="基本属性" DisplayOrder="3" Name="BindingIsChecked"/>
<mypro:PropertyDefinition DisplayName="路径" Category="基本属性" DisplayOrder="3" Name="Source" />
<mypro:PropertyDefinition DisplayName="图片路径" Category="基本属性" DisplayOrder="3" Name="ImageStartPath" />
<mypro:PropertyDefinition DisplayName="FontSize" Category="基本属性" DisplayOrder="4" Name="FontSize"/>
<mypro:PropertyDefinition DisplayName="字体" Category="基本属性" DisplayOrder="4" Name="FontFamily"/>
<mypro:PropertyDefinition DisplayName="字体样式" Category="基本属性" DisplayOrder="4" Name="FontWeight"/>
@@ -313,7 +313,7 @@
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="Source">
<mypro:EditorTemplateDefinition TargetProperties="ImageStartPath">
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<Grid>


+ 1
- 0
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs View File

@@ -46,6 +46,7 @@ namespace BeDesignerSCADA.Controls
InitializeComponent();
EditorHelper.Register<BindingExpression, BindingConvertor>();
Path = _Path;
viewModel.LayoutsPath=Path;
this.DataContext = viewModel;
viewModel.Loaded(cav, runCanvas);
//控件加载


+ 36
- 7
BeDesignerSCADA/ViewModel/MainViewModelNew.cs View File

@@ -18,6 +18,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -47,7 +48,10 @@ namespace BeDesignerSCADA.ViewModel
/// 变量管理器地址
/// </summary>
public string VariablePath = string.Empty;

/// <summary>
/// 布局路径
/// </summary>
public string LayoutsPath = string.Empty;
/// <summary>
/// 是否正在运行状态
/// </summary>
@@ -262,8 +266,8 @@ namespace BeDesignerSCADA.ViewModel
object selectpro = _property.SelectedProperty;


object selectControl= _property.SelectedObject;//对象
string selectProName= _property.SelectedProperty.ToString();
object selectControl = _property.SelectedObject;//对象
string selectProName = _property.SelectedProperty.ToString();

//选中属性
DependencyProperty dependencyProperty = PropertyHelper.GetDependencyProperties(selectControl)?.ToList().Find(x => x.Name == selectProName);
@@ -272,11 +276,11 @@ namespace BeDesignerSCADA.ViewModel
string _binding = PropertyBindingWindow.ShowEdit(dependencyProperty, (selectControl as FrameworkElement), VariablePath);
if (!string.IsNullOrEmpty(_binding))
{
Binding bindingText = new Binding()
{
Binding bindingText = new Binding()
{
Mode = BindingMode.TwoWay,
Converter= new JTokenToBoolConverter(),
RelativeSource =new RelativeSource { Mode=RelativeSourceMode.Self},
Converter = new JTokenToBoolConverter(),
RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self },
Path = new PropertyPath(_binding)
};
(selectControl as FrameworkElement).SetBinding(dependencyProperty, bindingText);
@@ -324,6 +328,31 @@ namespace BeDesignerSCADA.ViewModel
if (ofd.ShowDialog() == true)
{
((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = ofd.FileName;

if (!string.IsNullOrEmpty(LayoutsPath))
{
string qz = Path.GetDirectoryName(LayoutsPath);
if (!string.IsNullOrEmpty(qz) && qz.Contains("Layouts"))
{
string path = ofd.FileName;
string path2 = $"{qz.Replace("Layouts", "Images")}/{ofd.SafeFileName}";
FileInfo fi1 = new FileInfo(path);
FileInfo fi2 = new FileInfo(path2);
try
{
if (File.Exists(path2))
{
fi2.Delete();
}
fi1.CopyTo(path2);
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
}

}
}
}
}



Loading…
Cancel
Save