我可以为长文本消息设置文本包装模式,以将文本传输到Prism 6.2中的下一行.模态对话框? [英] 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?

查看:63
本文介绍了我可以为长文本消息设置文本包装模式,以将文本传输到Prism 6.2中的下一行.模态对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,模态对话框的通知消息文本很长,如下图所示.这不是自定义模式对话框,而是简单的通知模式对话框,其中包含一个非常长的短信.这是我在应用程序中使用的MODBUS协议库产生的异常错误消息.但是,SQL Server异常也可能包含有关错误的非常长的文本消息.默认情况下,Prism 6.2模态通知对话框显示不换行的文本.结果,模式对话框很长,并且错误消息的所有文本都没有放置并显示在对话框中.以下是此模式对话框的XAML标记:

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>

以下是此对话框的View Model C#代码:

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); }
}

下面的代码行来自View Modal构造函数:

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."; });
}

我可以为长文本消息(在XAML或View Model中)设置文本包装模式,以将文本传输到Prism 6.2中的下一行.模态对话框?

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?

推荐答案

您可以在PopupWindowAction中显示所需的任何视图,只需将内容添加到PopupWindowAction:

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>  

现在MyFancyErrorPopup可以将您的错误消息显示为多行文本框或您喜欢的任何内容...

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

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

这篇关于我可以为长文本消息设置文本包装模式,以将文本传输到Prism 6.2中的下一行.模态对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆