简体   繁体   English

Windows Phone中带有Caliburn Micro的弹出窗口

[英]Popup with Caliburn Micro in Windows Phone

Could anyone explain how to use the XAML popups with Caliburn Micro. 谁能解释如何在Caliburn Micro中使用XAML弹出窗口。

Thanks 谢谢

Edit:(Made my code more releavent to what I want to achieve) When I define a popup in xaml like this: 编辑:(使我的代码更轻松地实现了我想要实现的功能)当我在xaml中定义一个弹出窗口时,如下所示:

<Button x:Name="ShowPopup" Content="Popup"/>
<Popup x:Name="my_popup_xaml" Grid.Row="2">
    <Border  BorderThickness="2" Margin="10" BorderBrush="Green">
        <StackPanel Background="LightBlue">
            <TextBlock Text="Select Option" FontSize="21" Margin="10,0" />
            <StackPanel Orientation="Horizontal" Margin="0,10">
                <Button x:Name="SelectPhoto"  Content="Select photo From Library" Width="215"/>
                <Button x:Name="CapturePhoto"    Content="Use Camera"   Width="215"/>
            </StackPanel>
        </StackPanel>
    </Border>
</Popup>

How do I display this popup using the WindowManager? 如何使用WindowManager显示此弹出窗口?

Should I create new View Model for this because I just need to use PhotoChooser task and the Camera Capture task here? 我是否应该为此创建新的视图模型,因为我只需要在此处使用PhotoChooser任务和Camera Capture任务?

How do I bind Popup to my View Model. 如何将Popup绑定到我的视图模型。

Edit: 编辑:

@Charleh, Your Suggestion for using with windowmanager with a separate ViewModel worked, with a minor tweak. @Charleh,您对与单独的ViewModel与windowmanager一起使用的建议工作了,但做了一些细微调整。

I removed the <Popup> tag and used the window manager to display the popup. 我删除了<Popup>标记,并使用了窗口管理器来显示弹出窗口。

But now I cannot close the popup and the popup is cropped as it's displayed at the top of the screen. 但是现在我无法关闭弹出窗口,并且该弹出窗口在屏幕顶部显示时被裁剪。 How do I fix this? 我该如何解决?

Edit: I was able to close the dialog using the the Screen's TryClose() Method. 编辑:我能够使用屏幕的TryClose()方法关闭对话框。

When I used the ShowDialog method instead the of the ShowPopup method and the alignment of the window was a bit better but it is still stuck at the top and wont align in the center. 当我使用ShowDialog方法而不是ShowPopup方法时,窗口的对齐方式要好一些,但是它仍然停留在顶部,而不会在中心对齐。

对话画面

Edit: I have created a new PhoneApplicationPage(Windows Phone 8 equivalent of window) and displayed it as a dialog. 编辑:我创建了一个新的PhoneApplicationPage(相当于Windows Phone 8的窗口),并将其显示为对话框。 The problem with this approach is that the PhoneApplicationPage is not stretching automatically to fill the screen space(Which it does when not displayed as a dialog). 这种方法的问题在于PhoneApplicationPage不会自动拉伸以填充屏幕空间(当未显示为对话框时会这样做)。 It's just stretching to accommodate the content inside it. 它只是在拉伸以容纳其中的内容。 Setting `VerticalAlignment="Stretch" has no effect. 设置`VerticalAlignment =“ Stretch”无效。

Giving the Height property a particular value is not suitable because of it does not adjust to well to different phone resolutions. Height属性指定一个特定的值是不合适的,因为它不能很好地适应不同的电话分辨率。

@Charleh I tried specifying height and width like this: @Charleh我尝试像这样指定高度和宽度:

Dictionary<string, object> properies = new Dictionary<string, object>();
properies.Add("Height", 768);
properies.Add("Width", 480);
windowManager.ShowDialog(new ImageSelectorPopupViewModel(),null,properies);

This Code has no effect (although specifying the height in Xaml works but I cannot use that as I have to accommodate for different screen resolutions on the phone) 该代码无效(尽管在Xaml中指定高度有效,但由于必须适应手机上的不同屏幕分辨率,因此无法使用该高度)

You really need to read up on Caliburn Micro before you post - there are literally tons of articles showing how to bind commands on your view to methods on your VM 在发布之前,您确实需要阅读Caliburn Micro-大量文章显示了如何将视图上的命令绑定到VM上的方法

To do so in this case either: 为此,请执行以下任一操作:

  1. Bind using convention by giving your button the same name as the method 通过为按钮赋予与方法相同的名称来使用约定进行绑定

    <Button x:Name="ShowPopup" />

  2. Bind using action message syntax: 使用动作消息语法进行绑定:

    <Button cal:Message.Attach="[ShowPopup]" />

All the answers are here: http://caliburnmicro.codeplex.com/documentation 所有的答案都在这里: http : //caliburnmicro.codeplex.com/documentation

(specifically: http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation ) (具体是: http : //caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation

You do the same thing with your button, so you can do the same thing with your popup 您可以使用按钮执行相同的操作,因此可以使用弹出窗口执行相同的操作

(have you also considered using Caliburns WindowManager which has a ShowPopup method?) (您是否还考虑过使用具有ShowPopup方法的Caliburns WindowManager?)

Edit: 编辑:

On re-reading it looks like you want to use the same ViewModel for your current View and Popup - is this the case or do you want a new ViewModel for your Popup? 重新读取后,您似乎想为当前的View和Popup使用相同的ViewModel-是这种情况还是要为Popup使用新的ViewModel? I'd suggest using WindowManager, and creating a ViewModel for the popup - it will be more in-line with what CM already does 我建议使用WindowManager,并为弹出窗口创建一个ViewModel-这将更符合CM的功能

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

相关问题 Caliburn Micro:如何在 Windows 手机 silverlight 中导航 - Caliburn Micro: how to navigate in Windows phone silverlight Windows Phone Caliburn Micro HyperLink单击事件 - Windows Phone Caliburn Micro HyperLink click event 使用Caliburn.Micro在Windows Phone上进行Facebook身份验证回调 - Facebook authentication callback on Windows Phone using Caliburn.Micro Caliburn Micro:在Windows Phone模板中找不到方法的目标 - Caliburn Micro: no target found for method in Windows Phone template 返回到viewmodel禁用canexcute命令(Caliburn Micro-Windows Phone 8.1) - Return to viewmodel disables canexcute of commands (Caliburn Micro - Windows Phone 8.1) Caliburn.Micro 2.0并在Windows Phone 8.1 XAML中导航 - Caliburn.Micro 2.0 and navigating back in Windows Phone 8.1 XAML 如何使用Caliburn.Micro for Windows Phone修改共享对象 - How to modify a shared object with Caliburn.Micro for Windows Phone ListBox中的项目选择错误(Windows Phone,Caliburn.Micro,Rx) - Wrong item selection in ListBox (Windows Phone, Caliburn.Micro, Rx) Caliburn.Micro视图未在弹出窗口中销毁 - Caliburn.Micro view not destroyed in Popup 在Windows Phone 8.1上使用单个View查看多个ViewModel和Caliburn.Micro - Using single View for multiple ViewModels with Caliburn.Micro on Windows Phone 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM