2017-02-24 6 views
2

이 하나가 나와 함께 노는 것이고, 알아낼 수없는 것처럼 보입니다.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"및 "Cancel"버튼이 있지만 기본 설정이므로 원하지 않습니다. 그래서 "사용자 정의보기"방식을 사용했습니다. 여기

<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는 UserControl이 있습니다. 그래서

<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> 

당신이 볼 수 있듯이, 내가 UserControl을에서 "닫기"버튼이 있습니다

는 여기가 XAML의입니다.

커맨드를 사용해 보았습니다 만, 그때까지도 윈도우에 액세스 할 수 없거나 윈도우를 닫을 수 없습니다.

프리즘 명령이나 내가 모르는 뭔가가 있습니까?

버튼을 사용하여 원하는대로 창을 닫을 수 있습니까?

도움이 될 것입니다. :)

+0

당신이 당신의 자신의 문제를 해결했음을 알았습니다. FYI, Prism의 최신 문서는 http://prismlibrary.readthedocs.io/en/latest/에서 찾을 수 있습니다. MSDN 문서를 사용할 필요가 없습니다. –

답변

1

아무리해도 나는 이것을 스스로 해결할 수 없었다. :).

나는 다르게 생각하고 있었지만 실제로 원하는 것은 CancelCommand이었다.

다른 변경 사항없이 UserControl에서 구현하는 방법입니다. 전술 한 바와 같이 모두는 여전히 동일하지만 뷰 모델의에서 CustomPopup 이제 다음이 있습니다

public class CustomPopupViewModel : BindableBase, IInteractionRequestAware 
{ 
    public CustomPopupViewModel() 
    { 
     CancelCommand = new DelegateCommand(CancelInteraction); 
    } 

    private CustomPopupSelectionNotification notification; 

    public INotification Notification 
    { 
     get 
     { 
      return this.notification; 
     } 
     set 
     { 
      if (value is CustomPopupSelectionNotification) 
      { 
       this.notification = value as CustomPopupSelectionNotification; 
       this.OnPropertyChanged(() => this.Notification); 
      } 
     } 
    } 

    public Action FinishInteraction { get; set; } 

    public System.Windows.Input.ICommand CancelCommand { get; private set; } 

    public void CancelInteraction() 
    { 
     if (notification != null) 
     { 
      notification.SelectedItem = null; 
      notification.Confirmed = false; 
     } 

     FinishInteraction(); 
    } 
} 

당신은 또한 우리가 CustomPopupSelectionNotification라는 클래스를 가지고 있음을 알 수 있습니다. 대신 close에 노력하는,

public class CustomPopupSelectionNotification : Confirmation 
{ 
    public CustomPopupSelectionNotification() 
    { 
     Items = new List<string>(); 
     SelectedItem = null; 
    } 

    public CustomPopupSelectionNotification(IEnumerable<string> items) : this() 
    { 
     foreach (string item in items) 
     { 
      Items.Add(item); 
     } 
    } 

    public IList<string> Items { get; private set; } 

    public string SelectedItem { get; set; } 
} 

그래서 한마디로, 내가 단지 cancelling 팝업 :

는 여기 코드입니다이다.

그런 다음 CancelCommand 명령을 UserControl의 "닫기"버튼에 추가했습니다.