I’m trying to add a resource, which is a standard IValueConverter instance. I want to use that converter in XAML, but all I get is an exception saying that no resource found with provided key.
here’s the code:
public CallLogs(IMessenger messenger, IKernel kernel)
{
InitializeComponent();
_kernel = kernel;
var phoneToContactConverter = _kernel.Get<PhoneNumberToContactConverter>();
Resources.Add("PhoneNumberToContactConverter", phoneToContactConverter);
}
and here’s the XAML
<TextBlock Text="{Binding Number, Converter={StaticResource PhoneNumberToContactConverter}, ConverterParameter={Binding}}" />
I get an exception saying
{“Cannot find resource named ‘PhoneNumberToContactConverter’. Resource
names are case sensitive.”}.
Any idea how to reference resources from code behind?
Thanks.
I don’t have access to a C# compiler at the moment so can not try things out, but try moving the InitializeComponent() after the Adding of the resource. InitializeComponent does all the stuff specified in the XAML but the resource you are binding to does not exist at that point.