开发者

"key cannot be null" when parsing xaml in a datagrid text column

开发者 https://www.devze.com 2023-04-06 11:33 出处:网络
I have a DataGrid and it has a text column in it, configured this way: <dg:DataGridTextColumn Header=\"{x:Static ResViewModel:SC.Resources.HelloWorld}\" />

I have a DataGrid and it has a text column in it, configured this way:

  <dg:DataGridTextColumn Header="{x:Static ResViewModel:SC.Resources.HelloWorld}" />

Here ResViewModel is the xmlns:namespace, SC is the project namespace, Resources is the resource file name and HelloWorld is a string property.

But I try to parse this xaml, I get an error like

Key cannot be null. Parameter name: key...

Can you he开发者_StackOverflow社区lp me to understand why is this error occuring? Also what is the best way to access resource file without using the LocBAML tool?


I see some issues:

  1. "SC is the project namespace" - that should go into the xmlns definition.
  2. You can't access files with this syntax, unless you have a dependency object with the same name.

There's a good approach to retrieving strings that is described here. It's focusing on Localisation, but it will work for a single language as well. This approach has it's downsides, but it's the lesser evil than other routes.

0

精彩评论

暂无评论...
验证码 换一张
取 消