尝试在转换器中转换DesignTime数据时出现InvalidCastException [英] InvalidCastException when trying to cast DesignTime data in a converter
问题描述
我在Expression Blend 4.0中为Silverlight 3.0项目创建了一些设计时数据。我使用"从类创建示例数据..."创建了它。 Blend的Data选项卡中的选项。
示例数据的一个属性是一个自定义类,我们使用IValueConverter将其转换为Polygon上的一组Point。 COnverter中的代码执行此操作
var planPoints = ( 列表< PlanPoint >)值;
var points = new PointCollection () ;
planPoints.ForEach(pp => points.Add( new Point (pp.X, pp.Y)));
return points;
问题是值参数没有传入我们期望的类型。我们期待List< CompanyName.Data.PlanPoint>但我们得到List< _.di1.CompanyName.Data.PlanPoint>。
为什么混合使用似乎是代理类型的东西以及我们如何阻止它?
TIA
Pat Long
Pat Long munkiisoft blog
您需要将示例数据设置为使用真实类型而不是虚假类型。
这包括如何在VS中执行此操作。
干杯,
Karl
I have created some design time data in Expression Blend 4.0 for my Silverlight 3.0 project. I created it using the "Create Sample Data From Class.." option in the Data tab of Blend.
One of the properties on the sample data is a custom class that we convert to a set of Point on a Polygon using an IValueConverter. The code in the COnverter does this
var planPoints = (List<PlanPoint>)value;
var points = new PointCollection();
planPoints.ForEach(pp => points.Add(new Point(pp.X, pp.Y)));
return points;
The trouble is the value argument is not being passed in with the type we would expect. We are expecting List<CompanyName.Data.PlanPoint> but instead we are getting List<_.di1.CompanyName.Data.PlanPoint>.
Why is Blending using what seems to be a proxy type and how can we stop this?
TIA
Pat Long
Pat Long munkiisoft blog
You need to set the sample data to use Real Types instead of faux types.
This covers how to do this in VS.
Cheers,
Karl
这篇关于尝试在转换器中转换DesignTime数据时出现InvalidCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!