stepan.fiala
Topic Author
Posts: 5
Joined: 21 Jun 2021, 16:20

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

16 Jul 2021, 11:27

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?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

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

16 Jul 2021, 16:27

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));
 
stepan.fiala
Topic Author
Posts: 5
Joined: 21 Jun 2021, 16:20

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

16 Jul 2021, 17:02

Works! Thanks a lot for your help.

Who is online

Users browsing this forum: Google [Bot], vinick and 59 guests