User avatar
horeaper
Topic Author
Posts: 32
Joined: 22 Sep 2014, 12:50

Slash in ResourceDictionary Key not recognized

14 May 2018, 11:09

Giving one ResourceDictionary:
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <sys:String x:Key="LoginScreen/Guest">Guest</sys:String>
    <sys:String x:Key="LoginScreen/Register">Register</sys:String>
    <sys:String x:Key="LoginScreen/Login">Login</sys:String>
(...and the list goes on and on...)
Create and apply a simple view model:
public class ViewModel
{
    public ResourceDictionary Resources { get; } = LoadResourceDictionary();
}
(...inside some UserControl...)
DataContext = new ViewModel();
And use it like this:
<Button Content="{Binding Resources[LoginScreen/Login]}" Width="80" Height="25" />
It works fine under WPF, but Noesis (2.1.0f1 with Unity) shows:
NoesisException: Assets/Xaml/LoginWindow.xaml(65): Unable to convert 'Resources[LoginScreen/Login]' to a valid value for property Binding.
Rethrow as NoesisException
(wrapper dynamic-method) System.Object:lambda_method(System.Runtime.CompilerServices.Closure)
Rethrow as NoesisException
Rethrow as NoesisException
(wrapper dynamic-method) System.Object:lambda_method(System.Runtime.CompilerServices.Closure)
Rethrow as NoesisException
Seems Noesis doesn't understand the slash character. Changing it to underscore:
<sys:String x:Key="LoginScreen_Login">Login</sys:String>
(...)
<Button Content="{Binding Resources[LoginScreen_Login]}" Width="80" Height="25" /
Now it works.

But we have tens of thousands definitions using slash inside x:Key, do I have to change ALL of them?? Not to mention it's gonna cause conflicts since we also uses underscore.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Slash in ResourceDictionary Key not recognized

16 May 2018, 22:45

Hi, I can confirm it is a bug in our PropertyPath parser.
It will be fixed for the next release.

Who is online

Users browsing this forum: Roest, sfernandez and 0 guests