Value Converter not resolved in XAML class

316 Views Asked by At

I have a XAML file associated with a class that is not a UserControl descendant. I am trying to convert a string into a POCO using a value converter. This problem is I can't seem to get the converter to be picked up as a static resource. I get the following error:

The resource "myConverter" could not be resolved.

Any ideas?

XAML

<blst:StreamFactory
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:blst="clr-namespace:myNamespace">

    <blst:StreamFactory.Resources>
        <blst:StreamFormatConverter x:Key="MyConverter"/>
    </blst:StreamFactory.Resources>

    <blst:StreamFactory.AvailableStreams>
        <blst:StreamInfo>
            <blst:StreamInfo.Format>
                <Binding Converter="{StaticResource MyConverter}" ConverterParameter="MP3"/>
            </blst:StreamInfo.Format>
        </blst:StreamInfo>
    </blst:StreamFactory.AvailableStreams>

</blst:StreamFactory>

C#

class StreamFactory
    {
        public ResourceDictionary Resources { get; set; }

        public List<StreamInfo> AvailableStreams { get; private set; }
    }
1

There are 1 best solutions below

0
On

Declare StreamFormatConverter outside this xaml. For example: in App.xaml. I think your Resources not like UserControl.Resources. It maybe not loaded in Memory.