这是我想要将FrameworkElement附加到新窗口以将其发布到PNG文件时的错误.
所以我的想法是删除父子链接,调用我的方法,并使用以下代码再次添加子代:
this.RemoveLogicalChild(element);
PublishFrameworkElement(element, stream);
this.AddLogicalChild(element);
Run Code Online (Sandbox Code Playgroud)
但我得到了完全相同的错误......
我在这里看了很多关于这个错误的问题,但没有回答我的问题我错过了什么?
编辑:这是适合我的代码:
var element = _GeneratedContent as FrameworkElement;
var ParentPanelCollection = (element.Parent as Panel).Children as UIElementCollection;
ParentPanelCollection.Clear();
FileStream stream = [...]
if (element != null)
{
PublishFrameworkElement(element, stream);
ParentPanelCollection.Add(element);
}
stream.Close();
Run Code Online (Sandbox Code Playgroud) 我有一个这样的通用接口:
public interface IResourceDataType<T>
{
void SetResourceValue(T resValue);
}
Run Code Online (Sandbox Code Playgroud)
然后我得到了这个实现我的接口的类:
public class MyFont : IResourceDataType<System.Drawing.Font>
{
//Ctor + SetResourceValue + ...
}
Run Code Online (Sandbox Code Playgroud)
最后我得到了一个:
var MyType = typeof(MyFont);
Run Code Online (Sandbox Code Playgroud)
我现在想System.Drawing.Font
从MyType中获取Type!目前,我得到了这段代码:
if (typeof(IResourceDataType).IsAssignableFrom(MyType))
{
//If test is OK
}
Run Code Online (Sandbox Code Playgroud)
但是我没有设法在这里"提取"我的类型...我尝试了一些事情GetGenericArguments()
和其他事情,但他们要么不编译或返回空值/列表...我该怎么办?
编辑:这是适合我的代码的解决方案,为那些将得到同样问题的人:
if (typeof(IResourceDataType).IsAssignableFrom(MyType))
{
foreach (Type type in MyType.GetInterfaces())
{
if (type.IsGenericType)
Type genericType = type.GetGenericArguments()[0];
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
import QtQuick 1.0
ListModel {
property real firstValue: 2
property real secondValue: 3
property real thirdValue: 1
id: leftGrid
ListElement {
icon: "Images/1.png"
value: leftGrid.firstValue
}
ListElement {
icon: "2.png"
value: -1
}
ListElement {
icon: "3.png"
value: leftGrid.secondValue
}
ListElement {
icon: "4.png"
value: leftGrid.thirdValue
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
ListElement: cannot use script for property value
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我认为标题很清楚!
我现在拥有的是:
System.Drawing.Color uiui = System.Drawing.ColorTranslator.FromHtml(myString);
var intColor = (uint)((uiui.A << 24) | (uiui.R << 16) | (uiui.G << 8) | (uiui.B << 0));
var bytes = BitConverter.GetBytes(uint.Parse(value));
var brush = new SolidColorBrush();
brush.Color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
Run Code Online (Sandbox Code Playgroud)
1- myString就像我在标题中所说的那样#FFFFFF
2-这在BitConverter.GetBytes行上失败了,这让我感到惊讶,因为我得到了我的Color上的int表示!
3-无论如何,我知道COlor转换不是那么直观,但我觉得我做得不对......这是好方法吗?
可能重复:
突破嵌套循环
我得到的东西(简化)
foreach (...)
{
foreach (...)
{
//Some code
if (statement)
{
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我希望我的声明留给双foreach循环!我正在考虑将某种"破坏标志"作为布尔值,但是有什么方法可以避免这种情况吗?
我不会复制/粘贴我的整个xaml文件.解释它会太长,但这里有趣的是:我得到了一个属性"名称"的绑定
<TextBlock Text="{Binding Name}"/>
Run Code Online (Sandbox Code Playgroud)
问题是,有时,我的项目没有"名称"属性.它没有崩溃,但我只是在TextBlock中得到一个空文本
如果Name为空,我要做的就是绑定到"没有",只是{Binding}.这将显示我的对象名称,它将是完美的!
在此先感谢任何帮助,如果这是一个noobie问题,对不起:(
首先是LINQ中的菜鸟!那么,问题是我有一个集合:
我想使用Where但我不喜欢if
我必须做的说明......所以这是我的代码:
if (MyCollection.Any(rm => rm.BaseName == rbName))
{
var tmp = MyCollection.First(rm => rm.BaseName == rbName);
}
Run Code Online (Sandbox Code Playgroud)
这有效,但我真的觉得这不是我应该用LINQ做的方式......有什么建议吗?
我真的不知道要添加什么标题,我想获得Nullable的Type(T).例如,我得到了一个Type为Nullable的对象,我想得到像"System.Int32"这样的东西(当然不是字符串)
我得到以下生成DLL的代码(示例示例):
public class PluginClass
{
private string _MyString;
public string MyString
{
get { return _MyString; }
set
{
_MyString = value;
RaisePropertyChanged("MyString");
}
}
public int MyInt;
public SpeedGenerator SpeedGenerator1 = new SpeedGenerator();
public GaugeValueGenerator GaugeValueGenerator1
{
get;
set;
}
public PluginClass()
{
GaugeValueGenerator1 = new GaugeValueGenerator();
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我有4个字段/属性.
1个原始字段(primitive是int/string/bool/etcetc ...):MyInt 1原始属性:MyString 1对象字段:SpeedGenerator1 1对象属性:GaugeValueGenerator1
当我解析我的DLL时,我得做一些函数中的代码:WriteProperty
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
var props = type.GetProperties();
foreach (FieldInfo field in fields)
{
WriteProperty(field.FieldType, field.Name, XXX);
}
foreach (PropertyInfo prop …
Run Code Online (Sandbox Code Playgroud) 这是我用来检测我们是否正在处理Nullable类型的条件:
System.Nullable.GetUnderlyingType(itemType) != null
Run Code Online (Sandbox Code Playgroud)
这里是我队友的代码:
itemType.IsGenericType && itemType.GetGenericTypeDefinition() == typeof(Nullable<>)
Run Code Online (Sandbox Code Playgroud)
我们实际上并没有找到一个案例,其中一个将返回true
而另一个false
(或反之亦然),但这两个片段是否完全相同?