【问题标题】:Content property is set more than once内容属性设置了多次
【发布时间】:2015-11-06 00:42:21
【问题描述】:

我正在尝试在 4x4 网格上方的小空间中向我的 xaml 页面添加标题,但是当我尝试添加标签时,它显示内容已设置多次。

这是我的代码:

<Window x:Class="WpfApplicationAssignmentgood.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Grid Name="mainGrid" Margin="0,56,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
    </Grid>
    <Label Content="Hello" HorizontalAlignment="Center", VerticalAlignment="Center" FontFamily="Arial Black" FontSize="24" />

</Window>

【问题讨论】:

    标签: xaml


    【解决方案1】:

    您的Window 只能包含一个孩子。在您的情况下,您的 Window 包含一个 Grid 和一个 Label

    确保您的Window 只有一个孩子,您可以通过将Label 放在Grid 中来实现这一点。像这样的:

    <Window ... >
        <Grid>
            <Grid ...>
                ...
            </Grid>
    
            <Label Content="Hello" ... />
        </Grid>
    </Window>
    

    【讨论】:

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