小编And*_*rew的帖子

Silverlight 4数据绑定与样式

在我的silverlight应用程序中,我在页面上有一系列文本框,它们都以相同的方式绑定.在代码隐藏中,我设置每个的datacontext.有没有人使用样式来加入这种常见的绑定功能?

我的page.xaml中的示例

<TextBox Name="txtTest" Style="{StaticResource ItemTextBoxInt}"/>
Run Code Online (Sandbox Code Playgroud)

在我的Styles.xaml中

<Resource Dictionary>
<Style x:Key="ItemTextBoxInt" TargetType="TextBox">
<Setter Property="Text" Value="{Binding Amount, Mode=TwoWay, StringFormat=\{0:n0\}}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

这会在启动时在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)---内部异常堆栈跟踪结束---在系统.Windows.Application.LoadComponent(Object component,Uri resourceLocator)位于STARS_Silverlight.App.ctor()的STARS_Silverlight.App.InitializeComponent()中

任何人都知道这是否可能,如果是这样,正确的方法来实现这一目标?

-安德鲁

silverlight-4.0

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

标签 统计

silverlight-4.0 ×1