これは私と一緒に遊んでいて、私はそれを理解しているように見えない - 私はここで何か外部の助けが必要です!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
をしかし、私はまだこれを達成する方法を見つけ出すことはできません。基本ウィンドウには「OK」と「キャンセル」ボタンがありますが、これらはデフォルトであり、私はそれを望んでいません。そのため、私は「カスタムビュー」に行きました。ここ
<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>
そしてメインウィンドウのコード:
は、ここに私のメインウィンドウのXAMLで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>
あなたが見ることができるように、私は、ユーザーコントロールの「閉じる」ボタンがあります。
私はコマンドを使用しようとしましたが、それでも私はウィンドウにアクセスできないか、ウィンドウを閉じるために何かを実行できません。
プリズムコマンドなど何か気付いていないことがありますか?
ボタンでウィンドウを閉じることはできますか?
ご協力いただきますようお願い申し上げます。 :)
あなた自身の問題を解決してくれてうれしいです。 FYI、Prismの最新ドキュメントはhttp://prismlibrary.readthedocs.io/en/latest/でご覧いただけます。このために日付のMSDN記事を使用する必要はありません。 –