简体   繁体   English

如何在代码后面创建对象并在View中显示它?

[英]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.

相关问题 我如何在MVC中的代码后面创建按钮的onclick - How do I create a button's onclick in code behind in mvc 如何在 CREATE 视图中动态构建对象列表? - How do I dynamically build a list of objects in a CREATE view? 我如何在aspx页面上显示变量值后面的代码 - How do I display the code behind variable value on my aspx page 如何在我的代码后面的表中添加数据并以html显示? - How do I add data to a table in my code behind and display in html? 如何从Xamarin中的代码添加自定义视图以堆叠布局 - How do I add a custom view to stack layout from code behind in Xamarin 如何将XAML视图文件与其后面的代码重新连接? - How do I reconnect a XAML view file with it's code behind file? 如何在wpf app后面的代码中创建集合视图源 - How to create collection view source in code behind for wpf app 如何在后面的代码中创建HTML文档并将其加载到WPF浏览器中 - How do I create an HTML document in my code behind and load it into a WPF browser 如何在ASP.NET中的代码后面动态创建文件下载链接? - How do I dynamically create file download links in code behind in ASP.NET? 如何在没有代码隐藏文件的情况下创建ASMX Web服务页面 - How do I create an ASMX web service page without a code behind file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM