views:

32

answers:

1

At this point 2 Projection implementations are provided in Silverlight, but none of them really do what I want.

I need something like the PlaneProjector class but it only needs a RotationY property and it should raise an event whenever this property is changed.

I can't create a sub class from PlaneProjector as it is sealed, so my only remaining option (I think) is to create a sub class from System.Windows.Media.Projection... but I can hardly any information about this class.

Does anybody know how to implement your own custom Projectors for Silverlight?

Update

The thing is:

I have animations which change the RotationY property of the PlaneProjection. One animation from 0 to 180 One animation from 180 to 0

I need to be notified of every change to RotationY so I can update the UI properly.

+1  A: 

It is not possible to create custom implementation of Projection.

What is the issue with the PlaneProjection class? If the only issue is the lack of an event when the property changes, don't forget that you can data-bind to these properties and get notifications that way.

Here is one possibility. Instead of animating the RotationY property directly, you can animate a proxy value that is data-bound to the RotationY property. Here is an example class that you could use:

public class ValueProxy : FrameworkElement
{
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(object), typeof(ValueProxy), new PropertyMetadata(OnPropertyChanged));

    public object Value
    {
        get { return GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }

    private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ValueProxy obj = (ValueProxy)d;
        if (obj.PropertyChanged != null)
        {
            obj.PropertyChanged(obj, null);
        }
    }

    public event EventHandler PropertyChanged;
}

This class has an event that will fire whenever the "Value" property gets changed. Now you can use it in Xaml like so:

<Grid x:Name="LayoutRoot" >
    <Grid.Resources>
        <Storyboard x:Name="sb1">
            <DoubleAnimation Storyboard.TargetName="valueProxy" Storyboard.TargetProperty="Value" From="0" To="180" FillBehavior="Stop" />
        </Storyboard>
        <c:ValueProxy x:Name="valueProxy" Value="{Binding RotationY, ElementName=pp, Mode=TwoWay}" PropertyChanged="ValueProxy_PropertyChanged" />
    </Grid.Resources>

    <Button Content="Play Animation" Width="200" Height="200" Click="Button_Click" >
        <Button.Projection>
            <PlaneProjection x:Name="pp" RotationY="0" />
        </Button.Projection>
    </Button>
</Grid>

Notice that the animation is targeting the ValueProxy object and not the PlaneProjection. There is an event on ValueProxy that will notify you whenever the value changes. Does this help you achieve what you are trying to do?

KeithMahoney
Can you provide an example of what you mean... because I must be missing something very trivial here. (will add more details to the question)
TimothyP
I updated the answer with some code.
KeithMahoney