简体   繁体   English

如何通过Windows Store应用中的View Model在PopUp中显示图像

[英]How to show image inside PopUp via View Model in Windows Store apps

Hi I'm a newbie to windows store apps and i want to create a pop up that'll show image .I'm currently using Prism framework and tried many things.However , I'm successfully able to launch the pop up using code behind file but i need it from View Model class. 嗨,我是Windows存储应用程序的新手,我想创建一个将显示图像的弹出窗口。我目前正在使用Prism框架并尝试了许多操作。但是,我可以使用代码成功启动弹出窗口在文件后面,但是我需要View Model类。 Please help. 请帮忙。

You can use default winrt popups but if you want popups developed by yourself this is the way. 您可以使用默认的winrt弹出窗口,但是如果您想自己开发弹出窗口,则可以使用这种方法。

Create modal dialog user control, structure is following 创建模式对话框用户控件,结构如下

<Grid>
 <Grid Background="Black" Opacity="0.4"/>
  <Grid HorizontalAlignment="Center" VerticelAlignment="Center">
    <!-- your popup xaml -->
  </Grid>
</Grid>

Of course, you have to set ViewModel in some way, eg through ViewModelLocator 当然,您必须以某种方式设置ViewModel,例如通过ViewModelLocator

DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=ModalDialog}">

Add this user control to your main view ( root view ) or to all views where you want to have popup. 将此用户控件添加到主视图(根视图)或要弹出的所有视图中。

<controls:ModalDialog Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"/>

After this you can implement some service or use messenger to show dialogs. 之后,您可以实施一些服务或使用Messenger来显示对话框。 I know that it is maybe not so understandable but it is difficult to describe in all details. 我知道这可能不是那么容易理解,但是很难详尽描述。 Feel free to ask. 随便问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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