在我的silverlight应用程序中,页面上有一系列以相同方式绑定的文本框。在代码背后,我设置了每一个的datacontext。有没有人使用样式实现了这种常见的绑定功能?
我的page.xaml中的示例
<TextBox Name="txtTest" Style="{StaticResource ItemTextBoxInt}"/>在我的Styles.xaml
<Resource Dictionary>
<Style x:Key="ItemTextBoxInt" TargetType="TextBox">
<Setter Property="Text" Value="{Binding Amount, Mode=TwoWay, StringFormat=\{0:n0\}}"/>
</Style>这会在启动时在App.xaml.cs中抛出错误
{System.Windows.Markup.XamlParseException:设置属性'‘引发异常。行:9位置: 36 -> System.NotSupportedException:不能设置只读属性'‘。在MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken组件的MS.Internal.XamlMemberInfo.SetValue(对象目标,对象值),XamlQualifiedObject& inObj,XamlPropertyToken inProperty,XamlQualifiedObject& inValue) -内部异常堆栈跟踪的结束-在System.Windows.Application.LoadComponent(Object组件,Uri resourceLocator)在STARS_Silverlight.App.InitializeComponent()的STARS_Silverlight.App..ctor()}
有谁知道这是否可能,如果是的话,实现这一目标的正确方法是什么?
-Andrew
发布于 2011-04-20 21:43:32
不幸的是,SL4仍然不支持样式中的绑定。解决方法:http://blogs.msdn.com/b/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx
发布于 2011-02-03 05:14:20
验证Amount属性是否具有公开公开的setter。
https://stackoverflow.com/questions/4879850
复制相似问题