-4

I used MahApps.Metro in this window, I want to display SecondMainWindow when I click on a button but ShowDilaog method is not found I when I add anew WPF window with out MahApps.Metro the ShowDilag() method will found and it works fine the problem is I can't ShowDilag() to display a window that contains MahApps.Metro what is wrong with that code ?

here is the code I used to display SecondMainWindow in a button click

SecondMainWindow SMainWindow = new SecondMainWindow();

        SMainWindow.ShowDialog();

This error will appear

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'SecoundMainWindow' does not contain a definition for 'ShowDialog' and no accessible extension method 'ShowDialog' accepting a first argument of type 'SecoundMainWindow' could be found (are you missing a using directive or an assembly reference?)  
OneAppWPF   C:\Users\mypc\Desktop\SolucionApp\OneAppWPF\MainWindow.xaml.cs  83  Active

The SecoundMainWindow xaml code

<Controls:MetroWindow  x:Class="OneAppWPF.SecondMainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OneAppWPF"
         xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        mc:Ignorable="d"
        xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"


        Title="Second MainWindow" Height="450" Width="800">

    <Window.Resources>
        <Style x:Key="LargeTileStyle" TargetType="Controls:Tile">
            <Setter Property="Width" Value="300" />
            <Setter Property="Height" Value="125" />
            <Setter Property="TitleFontSize" Value="18" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>

        <Style x:Key="SmallTileStyle" TargetType="Controls:Tile">
            <Setter Property="Width" Value="147" />
            <Setter Property="Height" Value="125" />
            <Setter Property="TitleFontSize" Value="10" />
        </Style>




    </Window.Resources>


    <Controls:MetroWindow.LeftWindowCommands>
        <Controls:WindowCommands>
            <Button Content="settings" />
        </Controls:WindowCommands>
    </Controls:MetroWindow.LeftWindowCommands>


    <Grid x:Name="MainGridId">


    </Grid>
</Controls:MetroWindow>
MR_WELL
  • 87
  • 1
  • 10
  • 1
    A `MetroWindow` inherits from `Window` which indeed has a `ShowDialog` method. But looking at the code you have posted, the window in your XAML seems to be named "SecondMainWindo" (note the missing "w" at the end). So is `SecondMainWindow` really a window? – mm8 Apr 23 '20 at 12:44
  • Hi @mm8 I have missed w when I paste the code here – MR_WELL Apr 23 '20 at 12:46
  • And what is `SecoundMainWindow` in `Error CS1061 'SecoundMainWindow' does not contain a definition`? Note the `u`. – Clemens Apr 23 '20 at 12:53

1 Answers1

1

I Found the error SecoundMainWindow should inheritance from MetroWindow

public partial class SecoundMainWindow : MetroWindow
{
    public TestMainWindow()
    {
        InitializeComponent();
    }
}
MR_WELL
  • 87
  • 1
  • 10