【发布时间】:2011-09-12 07:50:03
【问题描述】:
给定以下 Xaml:
<Window.Resources>
<System:String x:Key="StringValue"></System:String>
</Window.Resources>
<Grid>
<ComboBox Margin="137,101,169,183" ItemsSource="{Binding collection}" SnapsToDevicePixels="True" IsHitTestVisible="true">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Command="{Binding CheckCommand}" IsChecked="{Binding IsChecked}" Content="{Binding Name}"/>
<TextBlock Text="{StaticResource StringValue}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
我想要的是将 Textblock Text 绑定到静态资源,即数据绑定到 ViewModel 上的值。问题是 System.String 似乎不允许数据绑定。有人知道这样做的方法吗?对于上下文,TextBlock 需要与其父组合框不同的 itemssource。
谢谢。
【问题讨论】:
-
您是否包含了 mscorlib 的别名?
xmlns:System="clr-namespace:System;assembly=mscorlib"没有错误出现。 -
查看我的编辑,寻找可能的包装类,它允许检测字符串的更新
标签: c# wpf xaml binding resources