Changing TransitionElement Content from a UserControl hosted in a Window

Jun 22, 2009 at 7:39 AM
Edited Jun 22, 2009 at 7:46 AM

I'm trying to change the TransitionElement Content property directly via a button within a User control.

Here is the main window XAML:

 

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:transitionalsControls="clr-namespace:Transitionals.Controls;assembly=Transitionals"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" Name="Window1">
    <DockPanel Name="LayoutRoot">
        <DockPanel Name="Buttons" DockPanel.Dock="Top">
            <Button Height="23" Name="Button1" DockPanel.Dock="Left" Width="135">Back</Button>
            <Button Height="23" Name="Button2" DockPanel.Dock="Right">Next</Button>
        </DockPanel>
        <transitionalsControls:TransitionElement x:Name="TransitionBox" DockPanel.Dock="Bottom" />
        
    </DockPanel>
</Window>
I can successfully change the content via buttons on the same window as the TransitionElement, but as soon as I try to change the content via an object not directly in the same windows as the TransitionElement, it just doesn't change the content. The Transition Begin and End events still fire, but the content doesnt change.

I have tried both directly calling the content change, and also via the dispatcher such as this:

Partial Public Class UserControl1

Public Delegate Sub ButtonClickDelegate()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
My.Windows.Window1.Dispatcher.Invoke(New ButtonClickDelegate(AddressOf ButtonClick), Windows.Threading.DispatcherPriority.Normal)
End Sub

Private Sub ButtonClick()
My.Windows.Window1.TransitionBox.Content = My.Windows.Window1.ObjectA
End Sub
End Class


And the code behind the main window:

 

Imports Transitionals

Class Window1

    Public ObjectA As New Button
    Public ObjectB As New UserControl1


    Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Me.Width = 320
        Me.Height = 480

        ObjectA.Content = "Object A"
        Me.TransitionBox.Transition = New Transitionals.Transitions.FadeAndBlurTransition
        Me.TransitionBox.Content = ObjectA
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Me.TransitionBox.Content = ObjectB
    End Sub

    Public Sub Button1_Click() Handles Button1.Click
        Me.TransitionBox.Content = ObjectA
    End Sub
End Class

 

 


Any hints?

 

Jun 22, 2009 at 12:41 PM

The only way I could get this to work was to raise an event from the usercontrol when I wanted to change the transitionbox content, then handle that event in the main window.

Is there a better way?

Aug 19, 2009 at 9:27 AM

 

Help Me Please

http://transitionals.codeplex.com/Thread/View.aspx?ThreadId=65559