Can I set text-wrapping mode for a long-text mesage to transfer the text to the next line in Prism 6.2. modal dialog?

那年仲夏 提交于 2019-12-25 09:01:43

问题


Sometimes the text of notification message for modal dialog is very long as you can see on the figure below.This 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?


回答1:


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
}


来源:https://stackoverflow.com/questions/39202336/can-i-set-text-wrapping-mode-for-a-long-text-mesage-to-transfer-the-text-to-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!