这是一个和我一起玩,我似乎无法弄清楚 - 我需要一些外部帮助在这里兄弟!WPF - PRISM:如何使用按钮点击关闭CustomPopupWindow
我想要一个没有标题,最小化,最大化和关闭按钮的弹出窗口,因为我们想自己设计样式,并在弹出窗口的屏幕上添加一个自定义关闭按钮。
所以我跟着这些链接来获得现在的我:
https://msdn.microsoft.com/en-us/library/ff921081(v=pandp.40).aspx https://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx https://www.codeproject.com/Articles/269364/MVVM-PRISM-Modal-Windows-by-using-Interaction-Requ
但我仍然无法弄清楚如何实现这一目标。基本的窗口有“确定”和“取消”按钮,但这些都是默认设置,我不想这样做,这就是为什么我选择“自定义视图”的原因。
这里是我的主窗口的XAML:
<Window x:Class="Prototype.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:views="clr-namespace:Prototype.Views"
Height="349.146" Width="727.317"
WindowState="Maximized">
<Grid>
<Button Command="{Binding RaiseCustomPopupViewCommand}">Show Popup Window</Button>
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding CustomPopupViewRequest, Mode=OneWay}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
<prism:PopupWindowAction.WindowStyle>
<Style TargetType="Window">
<Setter Property="ShowInTaskbar" Value="False"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="ResizeMode" Value="NoResize"/>
</Style>
</prism:PopupWindowAction.WindowStyle>
<prism:PopupWindowAction.WindowContent>
<views:CustomPopupView />
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
</Grid>
</Window>
这里,它的主窗口的代码:
public class MainWindowViewModel : BindableBase
{
public InteractionRequest<INotification> CustomPopupViewRequest { get; private set; }
public MainWindowViewModel()
{
CustomPopupViewRequest = new InteractionRequest<INotification>();
}
public DelegateCommand RaiseCustomPopupViewCommand => new DelegateCommand(RaiseCustomPopupView, CanRaiseCustomPopupView);
public string InteractionResultMessage { get; private set; }
private void RaiseCustomPopupView()
{
InteractionResultMessage = "";
CustomPopupViewRequest.Raise(new Notification { Content = "Message for the CustomPopupView", Title = "Custom Popup" });
}
private bool CanRaiseCustomPopupView()
{
return true;
}
}
的InteractionRequestTrigger
的SourceObject是一个用户控件。
这里是它的XAML:
<UserControl x:Class="Prototype.Views.CustomPopupView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:local="clr-namespace:Prototype.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
MinWidth="300" MinHeight="100">
<StackPanel Orientation="Vertical" Background="Gray">
<Button DockPanel.Dock="Right"
Content="Close"/>
</StackPanel>
</UserControl>
因此,大家可以看到,我在用户控件一个“关闭”按钮。
我尝试使用命令,但即使如此,我无法访问窗口或执行某些关闭窗口。
是否有某种棱镜命令或我不知道的东西?
是否可以通过按钮按照我想要的方式关闭窗口?
任何帮助将不胜感激! :)
很高兴看到你解决了你自己的问题。仅供参考,最新的棱镜文档可以在这里找到:http://prismlibrary.readthedocs.io/en/latest/。无需为此使用过时的MSDN文章。 –