【发布时间】:2012-02-21 18:00:23
【问题描述】:
我想本地化一个演示文稿,但我正在为这个演示文稿绞尽脑汁。我正在使用标记扩展,所以不要这样:
<DataGridTextColumn Header="Number" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
我想要这个:
<DataGridTextColumn Header="{Resx Key=Header_Number}" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
经过充分测试的标记只会返回当前文化的正确文本。但它不起作用。我假设我需要 HeaderStyle 或 HeaderTemplate 但是...
解决方法是什么?
干杯,
浆果
编辑
不工作我的意思是它在英文中没有返回文本“Number”,而是返回一个默认值(即“#Header_Number)。
正在工作,我的意思是
<Label FontWeight="Bold" Grid.Row="0" Grid.Column="0" Content="{Resx Key=Label_Amount}"/>
用英文返回“Amount”。
最终编辑
我的错,这实际上更多是因为 WPF 数据网格列不继承其父级的 DataContext。
标记扩展有一个 ResxName 属性,我喜欢为整个窗口设置一次:
resx:ResxProperty.Name="NMoneys.Presentation.Resources.AllocatorView"
Title="{Resx Key=Window_Title}"
但是由于数据网格中的标题不是可视化树的一部分(尽管看起来它们确实应该是!),所以我必须再次专门输入 Resx 的名称,如
<DataGridTextColumn Header="{Resx ResxName=NMoneys.Presentation.Resources.AllocatorView, Key=ColumnHeader_Number}" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
我之前遇到过这种情况,并看到了一些转发 DC 的技术,但在这种情况下,它不值得费心。
干杯,
浆果
【问题讨论】:
-
isn't working非常具体... -
@H.B.让我知道第 2 次迭代是否能更好地聚焦问题
-
这是更多信息,但您不认为扩展程序有问题吗?发布它的代码怎么样?
-
如果您认为它没有帮助,请发布或正确回答并接受它或删除问题,这很有可能。
-
我实际上认为它很有帮助,这就是为什么我没有删除它,也不会。将其开放一天,看看是否其他人对涉及 DataGrid 数据上下文转发的答案有不同的看法;如果不是,则将其设为可接受的答案。感谢您的意见!
标签: wpf silverlight datagrid datatemplate wpfdatagrid