2017-01-16 102 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