添加项目文件。

This commit is contained in:
wang-yin1
2025-07-14 21:08:46 +08:00
parent f4133fc5e9
commit 6deb8d089f
58 changed files with 5593 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace VisionFrame.Base.Converter
{
public class BoolToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (bool.Parse(value.ToString()))
return Brushes.LawnGreen;
else return Brushes.ForestGreen;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace VisionFrame.Base.Converter
{
public class LocationConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double.TryParse(values[0].ToString(), out double w);
double.TryParse(values[1].ToString(), out double h);
double w1 = w * 2;
double h1 = h * 2;
return new Thickness((w - w1) / 2, (h - h1) / 2, 0, 0);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace VisionFrame.Base.Converter
{
public class NodeJsonConverter : JsonConverter<NodeModelBase>
{
class TypeInfoTemp
{
public string TypeInfo { get; set; }
}
// 字符串到对象实例的转换过程
public override NodeModelBase? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string json = reader.GetString();// 包含程序信息
TypeInfoTemp ti = System.Text.Json.JsonSerializer.Deserialize<TypeInfoTemp>(json);
string[] type_info = ti.TypeInfo.Split(";");
Assembly assembly = Assembly.GetEntryAssembly();// 取当前执行的程序集
if (assembly.GetName().Name != type_info[0])
{
assembly = Assembly.LoadFile(Environment.CurrentDirectory + "/Activities/" + type_info[0] + ".dll");
}
// 最终要执的节点Model
Type type = assembly.GetType(type_info[1]);
NodeModelBase node = (NodeModelBase)System.Text.Json.JsonSerializer.Deserialize(json, type);
return node;
}
// 对象到Json字符串的转换过程
public override void Write(Utf8JsonWriter writer, NodeModelBase value, JsonSerializerOptions options)
{
// value--->Json
// writer--写
// 准备类型的记录
string type = value.GetType().FullName;
string assembly = value.GetType().Assembly.GetName().Name;
value.TypeInfo = assembly + ";" + type;
// 如果直接放value 会循环触发这个方法
// 用一个动态变量接收,
dynamic temp = value;
string json = System.Text.Json.JsonSerializer.Serialize(temp);
writer.WriteStringValue(json);
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VisionFrame.Base.Converter
{
public class SizeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double r = 2;
if (parameter != null)
{
double.TryParse(parameter.ToString(), out r);
}
// 实际的宽高值
// 将这个值乘2返回出去
if (value != null && double.TryParse(value.ToString(), out double new_value))
return new_value * r;
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace VisionFrame.Base.Converter
{
public class StringToNodeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string[] _info = value.ToString().Split(";");
Assembly assembly = Assembly.GetEntryAssembly();
Type type = assembly.GetType(_info[0]);
if (_info.Length == 2)
{
assembly =
Assembly.LoadFile(Environment.CurrentDirectory + "/Activities/" + _info[0] + ".dll");
if (assembly == null) return null;
type = assembly.GetType(_info[1]);
if (type == null) return null;
}
object instance = Activator.CreateInstance(type);
Binding binding = new Binding("DataContext.AnchorDownCommand");
binding.RelativeSource = new RelativeSource() { AncestorType = typeof(ItemsControl) };
(instance as NodeBase).SetBinding(NodeBase.AnchorDownCommandProperty, binding);
binding = new Binding("DataContext.AnchorUpCommand");
binding.RelativeSource = new RelativeSource() { AncestorType = typeof(ItemsControl) };
(instance as NodeBase).SetBinding(NodeBase.AnchorUpCommandProperty, binding);
return instance;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}