我在这个窗口中使用了MahApps.Metro,当我点击一个按钮时,我想显示SecondMainWindow,但是,我不知道该怎么办。显示Dilaog 方法没有找到我当我添加一个新的WPF窗口与出MahApps.Metro的ShowDilag()方法将发现,它工作正常的问题是我不能ShowDilag()显示一个窗口,包含MahApps.Metro什么是错的代码?
这里是我用来显示SecondMainWindow的按钮点击的代码。
SecondMainWindow SMainWindow = new SecondMainWindow();
SMainWindow.ShowDialog();
这个错误会出现
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
SecoundMainWindow的xaml代码。
<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>
我发现错误SecoundMainWindow应该从MetroWindow继承。
public partial class SecoundMainWindow : MetroWindow
{
public TestMainWindow()
{
InitializeComponent();
}
}