简体   繁体   中英

dynamically add images to view

I'm trying to make a carousel in my Xamarin application. Here I need to add navigation "dots" below my carousel, in order to intuitively show the user which slide is shown in the carousel.

The Carousel is initialized from a List of objects, which may vary in size, which naturally means that I have to place a corresponding amount of dots at runtime.

Currently, I have bounded a ViewModel to my View, which updates the content of the carousel through a PropertyChangedEventHandler . The updates are currently controlled with a timer.

To summarize, I want to know, how I can add <Image> elements via code-behind in a .xaml file. Furthermore, I want to understand how I can identify them uniquely so that I can access them and change the image, based on which page is shown in the carousel.

to add an Image (or any element) to a View at runtime

// XAML
<StackLayout x:Name="stack">
  ...
</StackLayout>

// in code behind
stack.Children.Add(new Image() { ... });

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