1

sA version of this question has already been asked here.

I think the answer is clear and concise, but I don't quite understand it, and I didn't think I should start a massive chain of comments trying to figure it out(as posted out is proper etiquette here)

I'd like to add an extra button in my MahApps.Metro Dialog. I need a Browse button so that a user can input a directory. This answer shows how to do that, but I don't quite understand since I'm fairly new to C# and WPF.

What I don't understand is exactly where in my xaml file I should be placing the <Style></Style> section.

If I'm correct in guessing that it can go anywhere outside of my <Grid></Grid> then I'm getting errors that I don't understand.

My current code .xaml file.

<Controls:MetroWindow x:Class="testApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"              
    Title="testApp" Height="auto" Width="auto"
    EnableDWMDropShadow="True"
    ResizeMode="CanResizeWithGrip"
    WindowTransitionsEnabled="False"
    WindowStartupLocation="CenterScreen" Loaded="OnLoaded">


  <Grid>
  <!--some content -->
  </Grid>


</Controls:MetroWindow>

If I insert the Style section above the Grid section I get an error The namespace "Dialog" is not defined

I thought the xmlns xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"should have added the Dialogs?

Once I'm able to get the style set, I imagine I just add the below code from the previous answer (with the buttons I'd like).

<Dialogs:CustomDialog x:Key="CustomDialogTest"
                    Style="{StaticResource NewCustomDialogStyle}"
                    Title="This dialog allows arbitrary content. It will close in 5 seconds."
                    x:Name="CustomTestDialog">
    <StackPanel>
        <TextBlock Height="30"
                Text="This dialog allows arbitrary content. You have to close it yourself by clicking the close button below."
                TextWrapping="Wrap"
                Foreground="{DynamicResource AccentColorBrush}" />
        <Button Content="Close Me!" />
    </StackPanel>
</Dialogs:CustomDialog>

What am I not understanding? Thanks in advance

Note

I didn't add my .cs code b/c I'm having no problem actually getting the standard async dialog showing.

Community
  • 1
  • 1
trueCamelType
  • 2,198
  • 5
  • 39
  • 76
  • I'm not sure if this is just a typo however your xmlns:Dialogs != Dialog:CustomDialog. – Ryan Searle Oct 23 '15 at 08:30
  • Sorry if this is me not understanding, but why would xmlns:Dialogs need to be equal to Dialog:CustomDialog. I assumed it should still be ```xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"``` since I'm just editing the style. – trueCamelType Oct 23 '15 at 15:24
  • 1
    Sorry, poor wording on my end... Your key for the reference to the namespace is 'Dialogs' yet you use 'Dialog' (no 's') in the xaml. For example instead of – Ryan Searle Oct 23 '15 at 15:53

1 Answers1

2

It turns out I was trying to do this correctly, but I was running into a problem explained here (The answer by Wouter).

It turns out I had to specify the assembly, so

    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"

Should be

    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"              

That cleared up my errors in the Style.

So in the end, what I had to set the style was:

<Control.Resources>
    <Style TargetType="{x:Type Dialogs:BaseMetroDialog}">

    </Style>

</Control.Resources>

with

    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"              

at the top.

Community
  • 1
  • 1
trueCamelType
  • 2,198
  • 5
  • 39
  • 76