Dynamic binding to change width and height of control

Shay Wilner 1,746 Reputation points
2020-07-30T22:24:36.257+00:00

Hi

I try to change the width and height of a relative panel but i can't see any change

Here the xaml

14603-xaml.png

and the code

Public NotInheritable Class MainPage  
    Inherits Page  
    Implements INotifyPropertyChanged  
    Private widthboard As Double  
    Private heightboard As Double  
    Public Property widthboardx As Double  
        Get  
            Return widthboard  
        End Get  
        Set(ByVal value As Double)  
            widthboard = value  
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(“widthboardx”))  
        End Set  
    End Property  
    Public Property heightboardx As Double  
        Get  
            Return heightboard  
        End Get  
        Set(ByVal value As Double)  
            heightboard = value  
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(“heightboardx”))  
        End Set  
    End Property  
  
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged  
  
    Private Sub valid_Click(sender As Object, e As RoutedEventArgs) Handles valid.Click  
        heightboardx = theheight.Text  
        widthboardx = thewidth.Text  
        panel.Opacity = 1  
  
    End Sub  
End Class  

Thanks

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

Accepted answer
  1. Fay Wang - MSFT 5,226 Reputation points
    2020-07-31T03:02:36.16+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The default mode of x:Bind is OneTime which means it only changes the value one time, if you want to update the value of the target when you change the width or height property, you need to set the mode as OneWay.

    .xaml:

    <RelativePanel x:Name="panel" Width="{x:Bind Path=widthboardx,Mode=OneWay}" Height="{x:Bind Path=heightboardx,Mode=OneWay}" RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True">
         ......
    </RelativePanel>
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.