0

When a button is clicked on my XML, an image tag is created and on object is added to my list in my viewmodel.

This is the object that is created

    public unit(float x, float y, int team)
    {
        this.X = x;
        this.Y = y;
        this.team = team;
        this.speed = speed;
        this.rect1 = new Rectangle(x, y, 0.1, 0.1);
    }

When a different button is clicked, the unit.x is increased by 0.05.

I wish to bind my image tag position to the x and y of its unit object.

So if I click the buy button 3 times without clicking the move button, there should be 3 image tags perfectly on top of each other.

This is how my image tag is handled

    <AbsoluteLayout>
        <ListView x:Name="units_list_view" ItemsSource="{Binding Unit_list}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Image Source="tank.png" AbsoluteLayout.LayoutBounds="{Binding rect1}" />
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </AbsoluteLayout>

It never moves even as x increases, and doesn't start at the x and y of the unit.

How can I set the absolute position of my image tag to the x and y value of the object it's bound to?

Here is all relevant code, just in case

https://github.com/tgmjack/absoloute_pos_prob

Ken White
  • 123,280
  • 14
  • 225
  • 444
tgm_learny
  • 11
  • 7
  • 1
    Items in a ListView will never appear directly on top of one another – Jason May 26 '23 at 22:34
  • what am i missunderstanding about then? i thought it was for absoloute positioning? – tgm_learny May 26 '23 at 23:54
  • That only applies to the direct children of the layout. Your Images are nested inside the ListView. You can probably use a BindableLayout and get rid of the ListView – Jason May 27 '23 at 00:06

0 Answers0