2017-01-16 103 views
0

嘿,我想弄清楚如何在我自己的应用程序中调用SampleMessageDialog。材料设计中的SampleMessageDialog WPF

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

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> 

当前wh en我点击它给出的错误按钮:

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

在线:

Await DialogHost.Show(sampleMessageDialog, "RootDialog") 

回答

1

你有中的任何地方申请的XAML一个DialogHost?

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

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

是可能的代码呢? – StealthRT

+0

当然。你现在在代码中添加你的应用内容吗?我不知道VB特定的语法,但是在将应用程序添加到窗口内容之前,添加一个DialogHost并将所述应用程序添加到DialogHost的内容中。 DialogHost扩展了ContentControl,所以就像那个标准控件一样使用它。 – Joe