【发布时间】:2014-03-06 19:13:56
【问题描述】:
好的,我有一个 Observable 集合,其中包含这样定义的字符串。
public ObservableCollection<string> OCGroundType { get; set; }
这个集合有资源键,所以我想要做的是使用这个代码
<ListBox HorizontalAlignment="Left" Height="110" Margin="156,23,0,0" VerticalAlignment="Top" Width="314" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=OCGroundType}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Path=, Source={StaticResource Resources}}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
所以我想要做的是给路径提供 itemsource 的值是可能的吗?
编辑
这就是静态资源“绑定”到的资源字典
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cultures="clr-namespace:Marcam.Cultures"
xmlns:properties="clr-namespace:Marcam.Properties">
<ObjectDataProvider x:Key="Resources" ObjectType="{x:Type cultures:CultureResources}" MethodName="GetResourceInstance"/>
</ResourceDictionary>
ObjectType 被“绑定”到的是一个返回当前 Resources.resx 的方法,如果我已经很好地理解它是如何工作的,因为我已经将此代码基于 WPF Localization
【问题讨论】: