小编olt*_*man的帖子

Children.Add(item)值不在预期范围内

我正在开发一个Silverlight 3应用程序,当我尝试将一个对象添加到Canvas时,会出现这个非常奇怪的错误.我的代码如下:

for (int i = 0; i < person.Children.Count; i++)
{
    //Add children in same position as parent
    Person child = person.Children[i];
    child.x_PositionTransform.X = person.x_PositionTransform.X;
    child.x_PositionTransform.Y = person.x_PositionTransform.Y;
    child.Click += new RoutedEventHandler(person_Click);
    x_LayoutRoot.Children.Add(child);
}
Run Code Online (Sandbox Code Playgroud)

我第一次使用它,它按预期工作.但是,当我在单击使用此代码创建的Person对象后点击x_LayoutRoot.Children.Add(child)时,我收到一个ArgumentException,告诉我"Value不在预期范围内".

但是,当我在将child添加到x_LayoutRoot.Children之前添加以下代码时,问题就会消失.

child.SetValue(Canvas.NameProperty, "child" + objCount++);
Run Code Online (Sandbox Code Playgroud)

为什么会这样?这是一个Silverlight错误,还是(更有可能)我错过了什么?

.net c# silverlight

11
推荐指数
1
解决办法
2万
查看次数

Xmlserializer没有序列化基类成员

在尝试使用XmlSerializer序列化一个类进行日志记录时,我遇到了这个非常奇怪的问题.该代码由wsdl.exe工具生成.序列化的类声明如下:

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "xxxxx")]
public partial class InheritedRequestA : BaseRequest
{
}
Run Code Online (Sandbox Code Playgroud)

同样继承自BaseRequest的其他类的序列化包括所有非继承成员,但不包括BaseRequest中的所有公共成员.BaseRequest声明如下.

[System.Xml.Serialization.XmlIncludeAttribute(typeof(InheritedRequestA))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(InheritedRequestB))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "xxxxx")]
public partial class BaseRequest
{
//members here
}
Run Code Online (Sandbox Code Playgroud)

为了将请求和响应一起序列化,我编写了一个非常基本的Wrapper类,它只包含一个请求对象和一个响应对象.序列化代码:

        XmlSerializer serializer = new XmlSerializer(typeof(Wrapper));
        string serializedObject = string.Empty;
        using (MemoryStream stream = new MemoryStream())
        {
            serializer.Serialize(stream, wrapper);
            stream.Position = 0;
            using (StreamReader reader = new StreamReader(stream))
            {
                serializedObject = reader.ReadToEnd();
            }
        }
Run Code Online (Sandbox Code Playgroud)

关于为什么从基类继承的公共属性没有被序列化的任何想法将不胜感激.

编辑:这是包装类.我将它子类化为ActivatorWrapper和VersionRetrieverWrapper.

[Serializable]
[XmlInclude(typeof(Wrapper))]
[XmlInclude(typeof(ActivatorWrapper))]
[XmlInclude(typeof(VersionRetrieverWrapper))]
public class Wrapper
{ …
Run Code Online (Sandbox Code Playgroud)

.net c# serialization xml-serialization

3
推荐指数
1
解决办法
5625
查看次数

wsdl.exe 生成的 WCF 服务公开 wsdl 中的私有字段

我正在使用 WCF 在 C# 中进行一些 wsdl 和客户端优先开发(wsdl 和客户端已经存在,我正在构建服务器端,)并且我遇到了一个奇怪的问题。我使用 wsdl.exe 从我的 .wsdl 生成合同,我能够构建它并将 WCF 服务作为 Windows 服务托管。

但是,我从http://localhost/Service?wsdl 获得的 wsdl公开了私有字段而不是公共属性(例如:而不是OsTypeI get m_OsTypeField,这是与公共OsType属性关联的私有变量。)

以下是有此问题的类之一的属性: [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xxxxxxx.com/")]

我完全被难住了,因为 .NET XML 序列化程序应该忽略任何私有成员。关于为什么会发生这种情况的任何想法?

.net c# wcf wsdl

2
推荐指数
1
解决办法
4250
查看次数

NSString sizeWithFont:constrainedToSize:未按预期工作

我正在尝试使用sizeWithFont,如下所示:

[commentTextLabel.text sizeWithFont:commentTextLabel.font
                  constrainedToSize:CGSizeMake(commentTextLabel.frame.size.width, CGFLOAT_MAX)
                      lineBreakMode:UILineBreakModeWordWrap];
Run Code Online (Sandbox Code Playgroud)

当我这样做时,我希望返回的CGSize具有与传入的相同的宽度(commentTextLabel.frame.size.width)但是,由于某种原因,尽管文本有足够的垂直空间来增长,但宽度正在减小.

以下是我看到的值:

  • 在: 360.000000, CGFLOAT_MAX
  • 日期: 335.000000, 88.000000

我只是误解了这个功能?如果是这样,我怎么能实现这个来确定约束到一定宽度时文本的高度?

iphone cocoa-touch ios

1
推荐指数
1
解决办法
3401
查看次数