简体   繁体   中英

Data type for binding x and y coordinates in AbsoluteLayout.LayoutBounds in Xamarin Forms

I have an array of data consisting body parts detail and I am using Absolute Layout. I only need to provide X and Y coordinates but I don't want to provide width and height which should be taken automatically.

So, the question is, what should be the DATA TYPE, if we need to bind the X and Y coordinate. I am using list view to bind all those data. eg.

AbsoluteLayout.LayoutBounds="0.80, 0.193"

AbsoluteLayout.LayoutBounds="0.4, 0.21"

代码示例绝对布局预览

使用位置比例时,可以自动调整宽度和高度。

AbsoluteLayout.LayoutBounds="0.4,0.21,-1,-1"

You can bind LayoutBounds as follow:

<ListView x:Name="EmployeeView" >
    <ListView.ItemTemplate>
      <DataTemplate>
        <AbsoluteLayout>
            <Label Text="I'm centered on iPhone 4 but no other device"
                AbsoluteLayout.LayoutBounds="{Binding rect1}" LineBreakMode="WordWrap"  />
            <Label Text="I'm bottom center on every device."
                AbsoluteLayout.LayoutBounds="{Binding rect2}" AbsoluteLayout.LayoutFlags="All"
                LineBreakMode="WordWrap"  />

        </AbsoluteLayout>
      </DataTemplate>
</ListView>

And Bindable property should be a Xamarin.Forms.Rectangle

double x,y,width,height;
x= 100;
y=100;
width = 100;
height = 100;
Xamarin.Forms.Rectangle rect = new Xamarin.Forms.Rectangle(x,y,width,height);

Employees employees = new Employees();
employees.rect = rect;
EmployeeView.ItemsSource = employees;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM