Silverlight: Cannot resolve TargetProperty or OMG how hard can it be to debug this cr...p

5 comments
Sorry for the title of this post, but a little bit frustrated after using a looong time to find out why my animations didn't work.

I tried rotating two usercontrols on a page, and I constantly got this runtime-error:

        Cannot resolve TargetProperty (UIElement.Projection).(PlaneProjection.RotationY) on specified object.

My setup was a kind of Master-Detail story, where I wanted the details usercontrol to rotate in when selecting an item in my master-control.
So I already had my ViewModel, my States and Messages setup and working.
Now I just wanted to try to get that sweet rotation thingie going, and that's the part that was giving me some headache:

My VisualState was something like this:

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="Visning">
                <VisualState x:Name="Liste">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="List"
                                        Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
                            <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                            <EasingDoubleKeyFrame KeyTime="00:00:00.2500000" Value="90">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <PowerEase EasingMode="EaseIn"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                            <DiscreteDoubleKeyFrame KeyTime="00:00:00.25" Value="-90" />
                            <EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <PowerEase EasingMode="EaseOut"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Details"
                                         Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00.25" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="List"
                                        Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00.25" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Detaljer">
                        …. the opposite….
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

And my two Usercontrols:

        <views:TilbudsListe x:Name="List">
        </views:TilbudsListe>
        <views:TilbudDetaljer x:Name="Details" Visibility="Collapsed">
        </views:TilbudDetaljer>

When using these Storyboards, I get the aforementioned runtime-exception:

        Cannot resolve TargetProperty (UIElement.Projection).(PlaneProjection.RotationY) on specified object.

I tried googling this, I checked my code, my xaml, my naming, my eyes, my keyboard…. etc but just couldn't get this to work.

Finally I saw someones examplecode, looking kind-of half finished I thought:
        <Rectangle x:Name="rectangle" Stroke="Black" Height="113" Width="170" Canvas.Left="102" Canvas.Top="83" Fill="#FFF64040">
                <Rectangle.Projection>
                        <PlaneProjection/>
         </Rectangle.Projection>
        </Rectangle>

At first I had just thought that the empty Rectangle.Projection properties was because of some code he had tried and then forgotten to remove.

But then it struck me; could this be the  "magic" needed for xaml/silverlight to put the missing properties on my usercontrols?

And it was. Here is the revised usercontrols:
        <views:TilbudsListe x:Name="List">
            <views:TilbudsListe.Projection>
                <PlaneProjection/>
            </views:TilbudsListe.Projection>
        </views:TilbudsListe>
        <views:TilbudDetaljer x:Name="Details" Visibility="Collapsed">
            <views:TilbudDetaljer.Projection>
                <PlaneProjection/>
        </views:TilbudDetaljer.Projection>
        </views:TilbudDetaljer>

This obviously (?) works, and my two views now rotate in and out.

Arrrgggggh!
I want the last two hours back!  Now!!

Better luck for anyone reading this…

rgds
Henri Merkesdal

Posted via email from Henris blogg

5 comments :

Post a Comment

Silverlight - templated usercontrols and automatic conversion

No comments
When changing from manually defining my fields and values in xaml,
to defining a custom/templated usercontrol some of my bindings stopped working.

I created a custom control with two properties,
FeltLabel
and
FeltVerdi

FeltVerdi was defined as a textbox, and in my generic.xaml I had content bound like this:
    <Style TargetType="local:DataFelt">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DataFelt">
                    <Grid>
                        ….
                            <TextBox Style="{StaticResource felt}"
                                        Text="{TemplateBinding FeltVerdi />
                        ….
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

This worked ok for most of the fields I bound to the ViewModel, but for a couple of fields it seemed as if the binding wasn't working anymore.

After doublechecking my code and bindings I couldn't find anything wrong, so I started to notice that the fields that wouldn't display anymore
were fields defined as numbers in my ViewModel.
It looked like the builtin automatic converters didn't work any more.

I googled it and found a post that helped me, see below.

The solution was to change the binding like this:

        <Style TargetType="local:DataFelt">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DataFelt">
                    <Grid>
                        ….
                            <TextBox Style="{StaticResource felt}"
                                        DataContext="{TemplateBinding FeltVerdi}" Text="{Binding}" />
                        ….
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

This way automatic conversion stilll works, and my numbers etc is displaying nicely

Might be helpful for others?

Rgds
Henri

Posted via email from Henris blogg

No comments :

Post a Comment