0

Sometimes the text of notification message for modal dialog is very long as you can see on the figure below.enter image description hereThis is not custom modal dialog but simple notification modal dialog which has a very long text mesage. This is the exception error-message produced by MODBUS protocol library that I use in my application. But SQL Server exceptions can also have such very long text messages about errors. By default, Prism 6.2 modal notification dialod displays a none-wrapped text. As a result of it, the modal dialog is very long and not all of the text of error-message is placed and displayed in the dialog. Below is the XAML markup for this modal dialog:

<prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest, Mode=OneWay}">
    <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True"/>
</prism:InteractionRequestTrigger>

And below is View Model C#-code for this dialog:

public InteractionRequest<INotification> NotificationRequest { get; private set; }

public String NotificationStatus
{
    get { return this._notificationStatus; }
    set { SetProperty(ref this._notificationStatus, value); }
}

The folowing line of code is from View Modal constructor:

this.NotificationRequest = new InteractionRequest<INotification>();

And the following is method displaying modal notification dialog:

private void raiseNotification(string message, string caption)
{
    this.NotificationRequest.Raise(
           new Notification { Content = message, Title = caption },
           n => { this.NotificationStatus = "The user was notified."; });
}

Can I set text-wrapping mode for a long-text mesage (in XAML or in View Model) to transfer the text to the next lines in Prism 6.2. modal dialog?

JIST
  • 1,139
  • 2
  • 8
  • 30
Prohor
  • 141
  • 1
  • 3
  • 12

1 Answers1

0

You can show any view that you want inside the PopupWindowAction, just add content to the PopupWindowAction:

<prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest, Mode=OneWay}">
    <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">

        <prism:PopupWindowAction.WindowContent>
            <views:MyFancyErrorPopup/>
        </prism:PopupWindowAction.WindowContent>        

    </prism:PopupWindowAction>
</prism:InteractionRequestTrigger>  

Now MyFancyErrorPopup can show your error message as a multi-line textbox or whatever you like...

EDIT:

<UserControl x:Class="ClientModule.Views.MyFancyErrorPopup"
     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"
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300">
    <StackPanel Orientation="Vertical">
        <TextBlock Text={Binding Message}" TextWrapping="Wrap"/>
        <Button Content="Ok" Command="{Binding OkCommand}"/>
    </StackPanel>
</UserControl>


class MyFancyErrorPopupViewModel : BindableBase, IInteractionRequestAware
{
    public MyFancyErrorPopupViewModel()
    {
        OkCommand = new DelegateCommand( OnOk );
    }

    public DelegateCommand OkCommand
    {
        get;
    }

    public string Message
    {
        get { return (_notification?.Content as string) ?? "null"; }
    }

    #region IInteractionRequestAware
    public INotification Notification
    {
        get { return _notification; }
        set
        {
            SetProperty( ref _notification, value as Notification );
            OnPropertyChanged( () => Message );
        }
    }

    public Action FinishInteraction
    {
        get;
        set;
    }
    #endregion

    #region private
    private Notification _notification;

    private void OnOk()
    {
        FinishInteraction();
    }
    #endregion
}
Haukinger
  • 10,420
  • 2
  • 15
  • 28
  • Should I define a View I want to use inside PopupWindowAction as UserControl or Window? – Prohor Aug 29 '16 at 14:14
  • Should I define a View Model for the View I want to use inside PopupWindowAction or not? – Prohor Aug 29 '16 at 14:16
  • The content will be a `UserControl`, and wether or not you want to use a view model, is up to you, but I'd say use one. Look at this for a bit more complex example: http://stackoverflow.com/questions/35238759/prism-custom-confirmation-interaction/35239947#35239947 – Haukinger Aug 29 '16 at 16:02
  • Your example is quite complex. Please give me a simple example just for my case. – Prohor Aug 30 '16 at 04:59
  • How to pass an error mesage to this dialog and how to display it? Can I use here the call of raseNotification method as in case of displaying of simple notification dialog in Prism? – Prohor Aug 31 '16 at 04:56
  • I changed '...' to ... and all works nice. Thanks for your help. – Prohor Aug 31 '16 at 06:46