Ste*_*hRT 1 vb.net wpf material-design material-ui
嘿,我想弄清楚如何在我自己的应用程序中调用 SampleMessageDialog。
到目前为止,这是我表单上应该打开消息框的按钮的代码:
Private Async Sub BrowseButton_Copy_Click(sender As Object, e As RoutedEventArgs) Handles BrowseButton_Copy.Click
msgBoxPop.showPop()
End Sub
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
最后这是用户控件:
<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>
Run Code Online (Sandbox Code Playgroud)
目前,当我单击按钮时,会出现以下错误:
附加信息:未加载 DialogHost 实例。
在线的:
Await DialogHost.Show(sampleMessageDialog, "RootDialog")
Run Code Online (Sandbox Code Playgroud)
您的应用程序的 XAML 中是否有 DialogHost?
它的一个好位置是在窗口的根部,并包含应用程序的其余部分:
<Window ....>
<materialDesign:DialogHost>
...your app
</<materialDesign:DialogHost>
</Window>
Run Code Online (Sandbox Code Playgroud)