wpf 在Prism 6.2模态对话框中,我可以为长文本消息设置文本换行模式以将文本转移到下一行吗?

frebpwbc  于 2023-02-25  发布在  其他
关注(0)|答案(1)|浏览(313)

有时候模式对话框的通知消息文本很长,如下图所示。x1c 0d1x这不是自定义模式对话框,而是简单的通知模式对话框,它有很长的文本消息。这是我在应用程序中使用的MODBUS协议库产生的异常错误消息。但是SQL Server异常也可以有关于错误的很长的文本消息。默认情况下,Prism 6.2模式通知对话框显示非换行文本。因此,模式对话框非常长,并且并非所有错误消息文本都放置和显示在对话框中。以下是此模式对话框的XAML标记:

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

下面是查看模型C#-此对话框的代码:

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

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

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

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

以下是显示模态通知对话框的方法:

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

我可以为长文本消息(在XAML或视图模型中)设置文本换行模式,以将文本转移到Prism 6.2模态对话框中的下一行吗?

oxcyiej7

oxcyiej71#

您可以在PopupWindowAction中显示任何想要的视图,只需向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可以将您的错误消息显示为多行文本框或任何您喜欢的格式...
编辑:

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

相关问题