Reputation: 10552
Hey all I am trying to figure out how to call the SampleMessageDialog in my own app.
So far this is the code i have for a button on my form that should open the message box:
Private Async Sub BrowseButton_Copy_Click(sender As Object, e As RoutedEventArgs) Handles BrowseButton_Copy.Click
msgBoxPop.showPop()
End Sub
And this is the 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
And finally this is the usercontrol:
<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>
Currently when I click the button it gives an error of:
Additional information: No loaded DialogHost instances.
on line:
Await DialogHost.Show(sampleMessageDialog, "RootDialog")
Upvotes: 1
Views: 3861
Reputation: 7004
Do you have a DialogHost in the XAML of the application anywhere?
A good place for it is right at the root, inside the window and containing the rest of your application:
<Window ....>
<materialDesign:DialogHost>
...your app
</<materialDesign:DialogHost>
</Window>
Upvotes: 5