【问题标题】:Does anyone use Mahapps dialogs in try/catch operator?有人在 try/catch 运算符中使用 Mahapps 对话框吗?
【发布时间】:2018-10-11 17:22:32
【问题描述】:

我正在尝试使用 Mahapps 对话框而不是默认的 WPF 消息框。

这样我在 WinForms 和默认 WPF 中使用 MessageBox。

 try
        {
            // do something    
        }

 catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Attention!");

        }

我的问题是如何对 Mahapps 对话框使用类似的方式? 需要一个例子。

提前致谢!

【问题讨论】:

    标签: c# wpf dialog messagebox mahapps.metro


    【解决方案1】:

    我遇到了类似的情况,我想要唯一的消息框。这是示例代码

    <Grid x:Name="Popup" Visibility="Visible" MouseDown="Popup_MouseDown">
            <Grid Background="Black" Opacity="0.5"/>
            <Border
            MinWidth="250" 
            BorderBrush="Black" 
            BorderThickness="12,6" 
            CornerRadius="200,0,200,100" 
            HorizontalAlignment="Center" 
            VerticalAlignment="Center" Margin="90,40,102,44" Height="235" Width="325" Background="White">
            </Border>
            <TextBlock x:Name="txtMessage" TextWrapping="Wrap" Margin="176,106,194,117"><InlineUIContainer>
                </InlineUIContainer></TextBlock>
            <Button x:Name="btnOK" Content="OK" HorizontalAlignment="Left" Margin="176,202,0,0" VerticalAlignment="Top" Width="40"/>
        </Grid>
    

    您会得到相同的结果,只需确保将 XAML 放在最后。对于 C# 部分,它的

     try
        {
            // do something    
        }
    
     catch (Exception ex)
        {
           Popup.Visibility = Visibility.Visible;
           txtMessage.Text = "Attention!!!";
        }
    

    MouseDown 事件是这样的,如果单击“消息框”,它就会消失

    【讨论】:

    • 谢谢!我将尝试该代码。如果它要与 ex 等系统异常一起工作,那就是重点。
    猜你喜欢
    • 2012-11-25
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 2021-11-25
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    相关资源
    最近更新 更多