Browse Source

更新

样式分支
fyf 2 years ago
parent
commit
095b84a6e6
3 changed files with 152 additions and 52 deletions
  1. +1
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheRadioButton.cs
  2. +93
    -0
      BeDesignerSCADA/Converters/BrowsableAttribute.cs
  3. +58
    -51
      BeDesignerSCADA/ViewModel/MainViewModel.cs

+ 1
- 1
BPASmartClient.SCADAControl/CustomerControls/TheRadioButton.cs View File

@@ -26,7 +26,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
SetCurrentValue(ContentProperty, "单选按钮");
//SetCurrentValue(ContentProperty, "单选按钮");
}
static TheRadioButton()
{


+ 93
- 0
BeDesignerSCADA/Converters/BrowsableAttribute.cs View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeDesignerSCADA.Converters
{
//
// 摘要:
// Specifies whether a property or event should be displayed in a Properties window.
[AttributeUsage(AttributeTargets.All)]
public class BrowsableAttribute :Attribute
{
//
// 摘要:
// Specifies the default value for the System.ComponentModel.BrowsableAttribute,
// which is System.ComponentModel.BrowsableAttribute.Yes. This static field is read-only.
public static BrowsableAttribute Default;

//
// 摘要:
// Specifies that a property or event cannot be modified at design time. This static
// field is read-only.
public static BrowsableAttribute No;

//
// 摘要:
// Specifies that a property or event can be modified at design time. This static
// field is read-only.
public static BrowsableAttribute Yes;

//
// 摘要:
// Gets a value indicating whether an object is browsable.
//
// 返回结果:
// true if the object is browsable; otherwise, false.
public bool Browsable { get; set; }

//
// 摘要:
// Initializes a new instance of the System.ComponentModel.BrowsableAttribute class.
//
// 参数:
// browsable:
// true if a property or event can be modified at design time; otherwise, false.
// The default is true.
public BrowsableAttribute(bool browsable)
{
this.Browsable = browsable;
}

//
// 摘要:
// Indicates whether this instance and a specified object are equal.
//
// 参数:
// obj:
// Another object to compare to.
//
// 返回结果:
// true if obj is equal to this instance; otherwise, false.
public override bool Equals([NotNullWhen(true)] object? obj)
{
throw null;
}

//
// 摘要:
// Returns the hash code for this instance.
//
// 返回结果:
// A 32-bit signed integer hash code.
public override int GetHashCode()
{
throw null;
}

//
// 摘要:
// Determines if this attribute is the default.
//
// 返回结果:
// true if the attribute is the default value for this attribute class; otherwise,
// false.
public override bool IsDefaultAttribute()
{
throw null;
}
}
}

+ 58
- 51
BeDesignerSCADA/ViewModel/MainViewModel.cs View File

@@ -274,55 +274,52 @@ namespace BeDesignerSCADA.ViewModel
{ "Code" , "代码过滤脚本"},
{ "GenerateData" , "数据结果"},
};
//{"EventSendNameList" , "发送事件集"}
/// <summary>
/// 数据刷新
/// </summary>
public void DataSX()
{
//if (CanSelectedItem is System.Windows.Controls.Control)
{
//属性变量
PropertyGridCommand cmd = new PropertyGridCommand();
var content = CanSelectedItem;// as System.Windows.Controls.Control;
if (content is IExecutable executable)
executable.PropertyChange += Executable_PropertyChange;
//属性变量
PropertyGridCommand cmd = new PropertyGridCommand();
var content = CanSelectedItem;// as System.Windows.Controls.Control;
if (content is IExecutable executable)
executable.PropertyChange += Executable_PropertyChange;

foreach (var item in EventName)
foreach (var item in EventName)
{
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key);
var propName = info?.GetValue(content,null);
if (info != null && (item.Key == "Content" ? (propName is string) : true))
{
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key);
var propName = info?.GetValue(content,null);
if (info != null && item.Key == "Content" ? (propName is string) : true)
{
//var taget = this.GetType().GetMembers().Where(t => t.Name.Equals("BrowsableTrue")).FirstOrDefault();
//var datas= CustomAttributeData.GetCustomAttributes(taget)[0];
//cmd.GetType().GetProperty(item.Value).CustomAttributes.Append(datas);
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName);
}
SetPropertyVisibility(cmd,item.Value,true);
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName);
}
else
{
SetPropertyVisibility(cmd,item.Value,false);
}
cmd.PropertyChanged += Cmd_PropertyChanged;
PropeObject = cmd;
}
cmd.PropertyChanged += Cmd_PropertyChanged;
PropeObject = null;
PropeObject = cmd;
}

/// <summary>
/// 内部属性变化通知
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Executable_PropertyChange(object? sender,EventArgs e)
{
System.Windows.Controls.Control content = CanSelectedItem as System.Windows.Controls.Control;
System.Reflection.PropertyInfo info = content.GetType().GetProperty("GenerateData");
var propName = info?.GetValue(content,null);
PropeObject.GetType().GetProperty("数据结果").SetValue(PropeObject,propName);
DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>();
Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { DevNameList.Add(key); });
}

[Browsable(true)]
public void BrowsableTrue() { }
[Browsable(false)]
public void BrowsableFalse() { }

/// <summary>
/// 修改属性后
/// </summary>
@@ -377,36 +374,46 @@ namespace BeDesignerSCADA.ViewModel
}
#endregion

#region 设置
#region 特性控制
/// <summary>
/// 设置Browsable特性的值
/// 通过反射控制属性是否可见
/// </summary>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <param name="visible"></param>
public void SetPropertyVisibility(object obj,string propertyName,bool visible)
public static void SetPropertyVisibility(object obj,string propertyName,bool visible)
{
//Type type = typeof(BrowsableAttribute);
//PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
//AttributeCollection attrs = props[propertyName].Attributes;
//type.GetProperty("Browsable").SetValue(attrs[type], visible);

//AttributeCollection attributes =
// TypeDescriptor.GetProperties(obj)[propertyName].Attributes;
//// Checks to see if the property is browsable.
//BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof(
//BrowsableAttribute)];

//if (myAttribute.Browsable)
//{
// // Insert code here.
//}

//PropertyDescriptorCollection appSetingAttributes = TypeDescriptor.GetProperties(obj);
//Type type = typeof(BrowsableAttribute);
//FieldInfo fieldInfo = type.GetField("_displayName", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance);
//fieldInfo.SetValue(appSetingAttributes["TextID"].Attributes[displayType], "修改后的文本ID");
Type type = typeof(BrowsableAttribute);
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
AttributeCollection attrs = props[propertyName].Attributes;
FieldInfo fld = CallPrivatevariables(type,"<Browsable>k__BackingField");
// FieldInfo fld = type.GetField("Browsable",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreReturn | BindingFlags.GetProperty);
fld.SetValue(attrs[type],visible);
}

/// <summary>
/// 获取指定对象的指定成员变量
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="name"></param>
/// <returns></returns>
public static FieldInfo CallPrivatevariables(Type type,string name)
{
//BindingFlags flag = System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.NonPublic;
//Type type = obj.GetType();
//var fieldInfos_ = type.GetField(name, flag);
var fieldInfos = (System.Reflection.FieldInfo[])((System.Reflection.TypeInfo)type).DeclaredFields;
FieldInfo fieldInfo_ = null;
foreach (FieldInfo fieldInfo in fieldInfos)
{
if (fieldInfo.Name == name)
{
return fieldInfo;// (T)fieldInfo.GetValue(obj);
}
}
//FieldInfo fieldInfo = type.GetField(name, flag);
return fieldInfo_;// (T)fieldInfo_.GetValue(obj);
}
/// <summary>
/// 设置Category特性的值
@@ -477,7 +484,7 @@ namespace BeDesignerSCADA.ViewModel
private string _文本1;
private object _变量;

[Category("基本属性"), Description("Name"), Browsable(true), PropertyOrder(1)]
[Category("基本属性"), Description("Name"), Browsable(false), PropertyOrder(1)]
public string 名称
{
get


Loading…
Cancel
Save