Resetting the XConstraint and YConstraint of an image that is in relative layout in Xamarin fomrs

I have a requirement in Xamarin formats where an image located in a RelativeLayout needs to be modified based on a condition. I can only get the condition through the code. Here is my code.

<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Test.Views.Home">  <ContentPage.Content>
<RelativeLayout>      
  <ContentView
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
            RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
  </ContentView>
  <Image Source="imageButton.png"
                     x:Name="FloatButton"
                     HeightRequest="100"
                     WidthRequest="100"
                     RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-98}"
                     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-113}"/>
</RelativeLayout>  </ContentPage.Content></ContentPage>

      

Here, if you see the RelativeLayout.YConstraint of Image element, I need to change the expression to

RelativeLayout.YConstraint = "{ConstraintExpression Type = RelativeToParent, Property = Height, Factor = 1, Constant = -250}" / ">

How can I do this with code? Please note that I need to install it like the previous xaml code, and on some conditions I get inside the code, I need to change the YConstraint like the above code. Can anyone help me?

0


source to share





All Articles