1 Star 0 Fork 0

lindx/NodeEditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Extensions.cs 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
lindx 提交于 1个月前 . new
using System;
using System.IO.Packaging;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Navigation;
namespace NodeEditor {
public static class Extensions {
public static Color GetUniqueColor(int integer) {
Random rnd = new Random(integer);
int hash = rnd.Next();
double iterator = Math.Abs((double)hash / (double)int.MaxValue);
byte high = 235;
byte low = 100;
if (iterator < 1.0 / 6.0) {
return Color.FromRgb(high, (byte)((iterator * 6.0) * high), low);
} else if (iterator < 2.0 / 6.0) {
return Color.FromRgb((byte)((2.0 - iterator * 6.0) * high), high, low);
} else if (iterator < 3.0 / 6.0) {
return Color.FromRgb(low, high, (byte)((iterator * 2.0) * high));
} else if (iterator < 4.0 / 6.0) {
return Color.FromRgb(low, (byte)((4.0 - iterator * 6.0) * high), high);
} else if (iterator < 5.0 / 6.0) {
return Color.FromRgb((byte)((iterator * 6.0 / 5.0) * high), low, high);
} else {
return Color.FromRgb(high, low, (byte)((6.0 - iterator * 6.0) * high));
}
}
public static void LoadViewFromUri(this UIElement userControl, string baseUri) {
try {
var resourceLocater = new Uri(baseUri, UriKind.Relative);
var exprCa = (PackagePart)typeof(Application).GetMethod("GetResourceOrContentPart", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { resourceLocater });
var stream = exprCa.GetStream();
var uri = new Uri((Uri)typeof(BaseUriHelper).GetProperty("PackAppBaseUri", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, null), resourceLocater);
var parserContext = new ParserContext {
BaseUri = uri
};
typeof(XamlReader).GetMethod("LoadBaml", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { stream, parserContext, userControl, true });
}
catch (Exception exception) {
Console.WriteLine("Initialize Component Error : " + exception);
}
}
public static bool AddVar(List<VarData> varList, string type, string name, out VarData varData) {
foreach (VarData v in varList) {
if (v.key == name) {
varData = null;
return false;
}
}
varData = new VarData {
type = type,
key = name
};
varList.Add(varData);
return true;
}
public static void DelVar(List<VarData> varList, string name) {
for (int i = 0; i < varList.Count; i++) {
if (varList[i].key == name) {
varList.RemoveAt(i);
return;
}
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/lindx-code/NodeEditor.git
git@gitee.com:lindx-code/NodeEditor.git
lindx-code
NodeEditor
NodeEditor
master

搜索帮助