【问题标题】:SampleMessageDialog in material design WPF材料设计 WPF 中的 SampleMessageDialog
【发布时间】:2017-01-16 05:49:47
【问题描述】:

大家好,我想弄清楚如何在我自己的应用程序中调用 SampleMessageDialog。

到目前为止,这是我的表单上应该打开消息框的按钮的代码:

Private Async Sub BrowseButton_Copy_Click(sender As Object, e As RoutedEventArgs) Handles BrowseButton_Copy.Click
    msgBoxPop.showPop()
End Sub

这就是showPop

Imports MaterialDesignThemes.Wpf
Imports newRegisterProg.MaterialDesignColors.WpfExample.Domain

Public Class msgBoxPop
    Public Shared Async Sub showPop()
        Dim sampleMessageDialog = New SampleMessageDialog()

        With sampleMessageDialog
            .Message.Text = "TEST!"
        End With

        Await DialogHost.Show(sampleMessageDialog, "RootDialog")
    End Sub
End Class

最后这是用户控件:

<UserControl x:Class="MaterialDesignColors.WpfExample.Domain.SampleMessageDialog"
             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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             mc:Ignorable="d" 
             x:Name="messagePOP"
             d:DesignHeight="300" d:DesignWidth="300"
             MaxWidth="400">
    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock x:Name="Message" 
                   Margin="0 6 0 0"
                   FontSize="18" Grid.Row="0"/>
        <Button Grid.Row="1" 
                IsDefault="True" Style="{DynamicResource MaterialDesignFlatButton}"
                HorizontalAlignment="Right"
                Margin="16 16 16 0"
                Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}">
            ACCEPT
        </Button>
    </Grid>
</UserControl>

目前,当我单击按钮时,会出现以下错误:

附加信息:未加载 DialogHost 实例。

上线:

Await DialogHost.Show(sampleMessageDialog, "RootDialog")

【问题讨论】:

    标签: wpf vb.net material-design material-ui


    【解决方案1】:

    在应用程序的 XAML 中是否有 DialogHost?

    它的一个好地方是在根目录,在窗口内并包含应用程序的其余部分:

    <Window ....>
        <materialDesign:DialogHost>
            ...your app
        </<materialDesign:DialogHost>
    </Window>
    

    【讨论】:

    • 当然。您现在是否在代码中添加您的应用内容?我不知道 VB 特定的语法,但是在将应用程序添加到 Window 的内容之前,添加一个 DialogHost 并将所述应用程序添加到 DialogHost 的内容中。 DialogHost 扩展了 ContentControl,因此只需像标准控件一样使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多