DataGridColumn 标题内容 WPF
我想要本地化一个演示文稿,但我的大脑在这个演示文稿上冻结了。我正在使用标记扩展,所以不是这样:
<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 但是...
修复方法是什么?
干杯,
Berryl
EDIT
By 不起作用,我的意思是它在英语中不返回文本“Number”,而是返回默认值(即“#Header_Number”)。
通过正在工作,我的意思是 的不好,这
<Label FontWeight="Bold" Grid.Row="0" Grid.Column="0" Content="{Resx Key=Label_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 的技术,但在这种情况下不值得麻烦
,
贝里尔
I want to localize a presentation and I'm having a brain freeze on this one. I'm using a markup extension, so instead of having this:
<DataGridTextColumn Header="Number" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
I want this:
<DataGridTextColumn Header="{Resx Key=Header_Number}" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
where the markup, which is well tested, will just return the right text for the current culture. But it isn't working. I assume I need either a HeaderStyle or HeaderTemplate but...
What is the fix?
Cheers,
Berryl
EDIT
By isn't working I mean it isn't returning the text "Number" while in English, and instead returning a default value (ie, "#Header_Number).
By is working, I mean that
<Label FontWeight="Bold" Grid.Row="0" Grid.Column="0" Content="{Resx Key=Label_Amount}"/>
returns "Amount" while in English.
FINAL EDIT
My bad, this is really more a result of the fact that WPF data grid columns to not inherit the DataContext of their parent.
The markup extension has a ResxName property which I like to set once for the entire window:
resx:ResxProperty.Name="NMoneys.Presentation.Resources.AllocatorView"
Title="{Resx Key=Window_Title}"
But since the headers in the data grid aren't part of the visual tree (although it sure seems they should be!), I have to specifically put the name of the Resx again, as in
<DataGridTextColumn Header="{Resx ResxName=NMoneys.Presentation.Resources.AllocatorView, Key=ColumnHeader_Number}" Binding="{Binding Number}" Width="60" CellStyle="{StaticResource NumberStyle}" />
I've run into this before and seen a few techniques to forward the DC, but in this case it isn't worth the bother.
Cheers,
Berryl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您有代表您的实体的模型。我所做的是使用数据注释。这是一个例子。编辑:提供带有屏幕截图的 MVVM 类
Model
标题内容将自动绑定到属性的显示。
ViewModel
View
然后是资源在 typeof(StringLibrary)
如您所见,显示的名称等于资源文件中的 ResourceKey 。大约 2-3 周前,当我使用 XML 进行开发和测试时,我首先想到了注释。但是像 AutoMapper 这样的东西可以将你的对象映射到像这样的 pocos,或者你甚至可以使用 WCF RIA 服务,并且你可以有类似的注释。 WCF RIA 实际上是使用它们的人,但我只是以不同的方式使用它们。
可能有一些技巧可以实现这一点。但当你这样做时,你确实得到了一个简单的解决方案。
我希望我已经提供了足够的信息。
I assume you have models representating your entities. What I've done is used data annotations. Here is the example. Edit: Provided MVVM classes with screenshots
Model
The header content will then automatically bind to the display of the property.
ViewModel
View
And then the resources in the typeof(StringLibrary)
As you can see the Name of the display is equal to the ResourceKey in the resources file. I came up with the annotations first when about 2-3 weeks ago when I was developing and testing with XML. But things like AutoMapper can map your objects to pocos like these or you can even Use WCF RIA services and you can have similiar annotations. WCF RIA is actually the one who is using them, but I just use them in a different way.
There might be a few tricks here and there to accomplish this. But when you do, you really get an easy solution.
I hope I've provided enough information.