Silverlight 4.0 Silverlight 4使用样式进行数据绑定
在我的silverlight应用程序中,页面上有一系列文本框,它们都以相同的方式绑定。在codebehind中,我正在设置每个代码的datacontext。有没有人使用样式来实现这种常见的绑定功能 范例 在my page.xaml中Silverlight 4.0 Silverlight 4使用样式进行数据绑定,silverlight-4.0,Silverlight 4.0,在我的silverlight应用程序中,页面上有一系列文本框,它们都以相同的方式绑定。在codebehind中,我正在设置每个代码的datacontext。有没有人使用样式来实现这种常见的绑定功能 范例 在my page.xaml中 <TextBox Name="txtTest" Style="{StaticResource ItemTextBoxInt}"/> 在my Styles.xaml中 <Resource Dictionary> <Style x:K
<TextBox Name="txtTest" Style="{StaticResource ItemTextBoxInt}"/>
在my 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.XamlMemberInfo.SetValue(对象目标,对象值)
在MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType、XamlQualifiedObject和inObj、XamlPropertyToken inProperty、XamlQualifiedObject和inValue)
---内部异常堆栈跟踪的结束---
位于System.Windows.Application.LoadComponent(对象组件,Uri resourceLocator)
在STARS_Silverlight.App.InitializeComponent()上
在STARS_Silverlight.App..ctor()}
有人知道这是否可能,如果可能,知道实现这一目标的正确方法吗
-Andrew验证
Amount
属性是否有公开的setter。不幸的是,SL4仍然不支持样式中的绑定。解决方法:该金额确实有一个公开的setter。仍然抛出相同的错误:(