【问题标题】:Why my xaml only shows a plain window show up with nothig in it为什么我的 xaml 只显示一个没有任何内容的普通窗口
【发布时间】:2012-08-27 19:11:58
【问题描述】:

我是 WPF、Xaml 的新手,并且是 C# 初学者!我一直在研究这个,我不知道为什么下面的 xaml 只显示一个普通的窗口。没有按钮,没有标题,没有内容。我会很感激你的指导。如果问我为什么必须使用 MediaChecker,我是按照 Stack Overflow 以下帖子中的示例进行的:

How do i navigate from one Xaml file to another?

提前致谢。

<Window x:Class="MediaCheckerWPF.AboutBox" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="About Media Checker" Height="300" Width="400" ResizeMode="NoResize" 
    ShowInTaskbar="False">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="28" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="200" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="Name:"/>
        <Label Grid.Row="1" Grid.Column="0" Content="E-Mail:"/>
        <Label Grid.Row="2" Grid.Column="0" Content="Comment:"/>
        <Button Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" 
            MinWidth="80" Margin="3" Content="START"  />
        <Button Grid.Column="1" Grid.Row="3" HorizontalAlignment="Right" 
            MinWidth="80" Margin="3" Content="STOP"  />

    </Grid>
</Window> 

【问题讨论】:

  • 您拥有的 XAML 渲染得很好。如果你得到一个空白窗口,那么我怀疑它与其他事情有关,例如没有启动正确的窗口。
  • 雷切尔;感谢您的回答帮助,问题是:没有启动正确的窗口。但是,我找不到投票支持您的方法。我想你必须选择答案,然后我才能给出我的反馈。再次感谢。
  • 很高兴帮助你:) 我在下面的答案中为你扩展了我的评论

标签: wpf windows visual-studio-2010 xaml


【解决方案1】:

您拥有的 XAML 渲染得很好。如果您得到一个空白窗口,那么我怀疑它与其他事情有关,例如启动不同的窗口。

App.xaml&lt;Application&gt; 标记的StartupUri 属性中再次检查正确的Window 是否启动

<Application x:Class="MediaCheckerWPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="AboutBox.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

【讨论】:

    【解决方案2】:

    检查 App.xaml 中的 StartupUri

    <Application x:Class="GabeTexFilestImport.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
    
        </Application.Resources>
    </Application>
    

    【讨论】:

      【解决方案3】:

      我注意到如果系统非常慢也会发生这种情况。比如说,您正在达到最大内存消耗,这会减慢您的系统。在这种情况下,我看到 xaml 窗口出现但完全空白,没有控件,没有最小值,最大值,关闭按钮,没有标题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多