PlaneProjection RotationX using DispatcherTimer

Shay Wilner 1,746 Reputation points
2020-07-22T15:50:38.243+00:00

Hi

I tried to make simple animation of plane rotation around x axis
i bind the rotationx with variable name xplane and increase it each n milliseconds but nothing happenned

here the xaml

 <RelativePanel x:Name="messagebox" CornerRadius="6,6,6,6" BorderThickness="3,3,3,3" RelativePanel.AlignHorizontalCenterWithPanel="True"
 RelativePanel.AlignVerticalCenterWithPanel="True" Width="250" Height="120" BorderBrush="CornflowerBlue" Opacity="0">
 <RelativePanel.Projection>
   <PlaneProjection RotationX= "{x:Bind Path= xplane }"/>
   </RelativePanel.Projection>

mainpagexaml.vb

Private WithEvents timermessage As New DispatcherTimer

Private Sub solution_Click(sender As Object, e As RoutedEventArgs) Handles solution.Click
        solution.IsEnabled = False
        flagsolution = True
        title.Text = "Click any square"
        xplane = 30
        messagebox.Opacity = 1
        timermessage.Interval = TimeSpan.FromMilliseconds(234)
        timermessage.Start()
    End Sub

Private Sub timermessage_Tick(sender As Object, e As Object) Handles timermessage.Tick
        xplane += 1
        If xplane > 90 Then
            timermessage.Stop()
        End If

    End Sub

Thanks

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Ken Tucker 5,861 Reputation points
    2020-07-23T00:41:38.46+00:00

    Make sure that xplane is a property. The class or page you are bound to must implement the INotifyPropertyChanged interface and raise the property changed event every time the xplane value changes. This will let the page know to update the controls the property is bound to

    https://surpavan.blogspot.com/2012/05/inotifypropertychanged-vbnet-simple-way.html

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points Microsoft Employee Moderator
    2020-07-23T05:33:24.303+00:00

    Hello,

    Welcome to Microsoft Q&A.

    If you want to bind the properties in the current page and make dynamic changes, you need to let the class inherit the INotifyPropertyChanged interface and configure the properties. In this way, when the properties are modified, the UI will be notified to change.

    Xaml

    <RelativePanel x:Name="messagebox" CornerRadius="6,6,6,6" BorderThickness="3,3,3,3" RelativePanel.AlignHorizontalCenterWithPanel="True"
                   RelativePanel.AlignVerticalCenterWithPanel="True" Width="250" Height="120" BorderBrush="CornflowerBlue" Opacity="0">
        <RelativePanel.Projection>
            <PlaneProjection RotationX= "{x:Bind Xplane, Mode=OneWay}"/>
        </RelativePanel.Projection>
    </RelativePanel>
    

    Xaml.vb

    Public NotInheritable Partial Class RelativePanelPage
        Inherits Page
        Implements INotifyPropertyChanged
    
        Private _xplane As Double
    
        Public Property Xplane As Double
            Get
                Return _xplane
            End Get
            Set(ByVal value As Double)
                _xplane = value
                OnPropertyChanged("Xplane")
            End Set
        End Property
    
        Private timermessage As DispatcherTimer = New DispatcherTimer()
    
        Public Sub New()
            Me.InitializeComponent()
            Xplane = 30
            timermessage.Interval = TimeSpan.FromMilliseconds(234)
            timermessage.Tick += AddressOf Time_Tick
            timermessage.Start()
        End Sub
    
        Private Sub Time_Tick(ByVal sender As Object, ByVal e As Object)
            Xplane += 1
            If Xplane > 90 Then timermessage.[Stop]()
        End Sub
    
        Public Event PropertyChanged As PropertyChangedEventHandler
    
        Public Sub OnPropertyChanged( ByVal Optional propertyName As String)
            PropertyChanged?.Invoke(Me, New PropertyChangedEventArgs(propertyName))
        End Sub
    End Class
    

    Thanks.

    0 comments No comments

  2. Shay Wilner 1,746 Reputation points
    2020-07-23T17:02:12.747+00:00
     implements INotifyPropertyChanged
          Public Property xplane As Double
                Get
                    Return xpl
                End Get
                Set(ByVal value As Double)
                    xpl = value
                    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(“xplane”))
                End Set
            End Property
            Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.