[英]How do I create objects behind code and display it in the View?
I'm having trouble understanding how to apply the MVVM pattern when I want to display dynamic amount of images in the View from the ViewModel. 当我想从ViewModel在View中显示动态数量的图像时,我无法理解如何应用MVVM模式。
I have a array of Images in the ViewModel and I want to display it in the view. 我在ViewModel中有一个图像数组,我想在视图中显示它。
How do I display it in the View the best way. 如何以最佳方式显示它。
Just use ItemsControl, bind the ItemsSource to your image list, and then add DataTemplate to your ItemsControl that takes care of the "displaying actual image" part. 只需使用ItemsControl,将ItemsSource绑定到图像列表,然后将DataTemplate添加到ItemsControl,它负责“显示实际图像”部分。
<DataTemplate x:Key="siteView" >
<Image Source="{Binding _Source}" />
</DataTemplate>
<ItemsControl ItemTemplate="{StaticResource siteView}"
ItemsSource="{Binding Path=YOURIMAGELIST"/>
wpf中MVVM的概念是View Binding ViewModel的DataContext。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.