ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Noesis cannot set property of converter from resource

18 Jun 2020, 21:55

EDIT: See post #3 for a more accurate description of the problem. It has nothing to do with resource dictionaries.

---------

I have a converter which has some properties. In a resource dictionary, I attempt to set some of these properties during the setup of the converter. This fails with a:
"[NOESIS/E] ResourceDictionary.xaml(6): StaticResource 'SomeColor' not found." error.

I've created a minimal example below. The extra Brushes.SomeBrush item in the resource dictionary is just to illustrate that the thing I'm trying to reference (StaticResource SomeColor) is indeed properly initialized and functioning. I only get the error when trying to apply it to the converter's property. This works in WPF.

Resource Dictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Tests">

    <Color x:Key="SomeColor">#ff00ff00</Color>
    <SolidColorBrush x:Key="Brushes.SomeBrush" Color="{StaticResource SomeColor}"/>
    <local:ReturnColorConverter x:Key="Converters.ReturnColorConverter" SomeColorProperty="{StaticResource SomeColor}"/>

</ResourceDictionary>
Converter:
    class ReturnColorConverter : IValueConverter
    {
        public Color SomeColorProperty { get; set; } = Colors.Red;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return SomeColorProperty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
MainWindow:
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    
    <Grid>
        <Rectangle>
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding Converter={StaticResource Converters.ReturnColorConverter}}"/>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
    
Last edited by ck_russ on 19 Jun 2020, 10:14, edited 3 times in total.

Tags:
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Noesis cannot set property of converter inside a resource dictionary

19 Jun 2020, 07:05

To clarify one thing, this is only for setting the property to another value within that resource dictionary. Everything works fine setting the property to a constant. So it's just that for some reason Noesis does not seem to be seeing the initialized value of the static resource in this context.
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Noesis cannot set property of converter inside a resource dictionary

19 Jun 2020, 10:09

I narrowed this down. The exact issue is simply setting a Converter property using a static resource. Here is a more succinct example where I do not use a resource dictionary at all. Instead all resources are defined in the main window. I create a resource (a brush) which is set to green. I then draw three rectangles. The first rectangle is using the resource directly without a converter. It should draw green. The second rectangle uses the converter without setting its brush property. It should draw red, the default value given inside the converter. The last rectangle is drawn after setting the converter's property to the static resource, so it should draw green.

In WPF I get Green-Red-Green
In Noesis I get Green-Red-[null]

I'd expect that since Noesis fails to find the resource I am trying to set the converter's property, it ends up not creating the converter. And so the final square when drawn with noesis ends up null.

Main Window
    <Window.Resources>
        <ResourceDictionary>
            <SolidColorBrush x:Key="LocalBrush" Color="Green"/>
            <local:ReturnColorConverter x:Key="Converters.ReturnColorConverterWithoutPropertySet"/>
            <local:ReturnColorConverter x:Key="Converters.ReturnColorConverterWithPropertySet" SomeBrushProperty="{StaticResource LocalBrush}"/>
        </ResourceDictionary>
    </Window.Resources>

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Rectangle Width="25" Height="25" Fill="{StaticResource LocalBrush}"/>
        <Rectangle Width="50" Height="10" Fill="Blue"/>
        <Rectangle Width="25" Height="25" Fill="{Binding Converter={StaticResource Converters.ReturnColorConverterWithoutPropertySet}}"/>
        <Rectangle Width="50" Height="10" Fill="Blue"/>
        <Rectangle Width="25" Height="25" Fill="{Binding Converter={StaticResource Converters.ReturnColorConverterWithPropertySet}}"/>
    </StackPanel>
    
Converter
    class ReturnColorConverter : IValueConverter
    {
        public Brush SomeBrushProperty { get; set; } = Brushes.Red;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return SomeBrushProperty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Noesis cannot set property of converter from resource

19 Jun 2020, 16:39

Hi, I was able to reproduce the problem, can you please report it in our bugtracker an we will fix it for the next release?
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Noesis cannot set property of converter from resource

19 Jun 2020, 21:31

Sure thing. Reported here: #1729
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Noesis cannot set property of converter from resource

22 Jun 2020, 11:08

Thanks for the report, we fxed it for the next release.
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Noesis cannot set property of converter from resource

25 Jun 2020, 07:02

Thanks, much appreciated!

Who is online

Users browsing this forum: No registered users and 2 guests