Page 1 of 1

Value cannot be assigned to the property (property has type 'Noesis.Effect', value has type 'DropShadowEffect')

Posted: 16 Jul 2021, 11:27
by stepan.fiala
I'm trying to create a custom control with a ContentEffect property.
public static readonly DependencyProperty ContentEffectProperty = DependencyProperty.Register("ContentEffect", typeof(Effect), typeof(ButtonWithImage), new PropertyMetadata(null));

public Effect ContentEffect
{
	get { return (Effect)GetValue(ContentEffectProperty); }
        set { SetValue(ContentEffectProperty, value); }
}
It should be a stylable property that applies an effect on the ContentPresenter:
<ContentPresenter x:Name="Text" HorizontalAlignment="Center" VerticalAlignment="Center" Effect="{Binding Path=ContentEffect, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
This is how the property is used:
 <Setter Property="ContentEffect">
            <Setter.Value>
                <DropShadowEffect BlurRadius="5"/>
            </Setter.Value>
 </Setter>
It works fine in WPF, however in Unity, it throws the following errors:
[noesis] Invalid value 'DropShadowEffect' for property 'Project.ButtonWithImage.ContentEffect' in Setter
[noesis] Value cannot be assigned to the property 'Project.ButtonWithImage.ContentEffect' (property has type 'Noesis.Effect', value has type 'DropShadowEffect')


I've tried to use type aliases (as described here) but it did not help.

Any ideas?

Re: Value cannot be assigned to the property (property has type 'Noesis.Effect', value has type 'DropShadowEffect')

Posted: 16 Jul 2021, 16:27
by sfernandez
I guess this is with Noesis 3.0.12, right? This looks like a bug we solved for the upcoming 3.1 version.
Until you upgrade there is a workaround, you can define the property of type object:
public static readonly DependencyProperty ContentEffectProperty = DependencyProperty.Register(
  "ContentEffect", typeof(object), typeof(CustomControl), new PropertyMetadata(null));

Re: Value cannot be assigned to the property (property has type 'Noesis.Effect', value has type 'DropShadowEffect')

Posted: 16 Jul 2021, 17:02
by stepan.fiala
Works! Thanks a lot for your help.