2015-11-06 76 views
0

我試圖在我的xaml頁面上添加一個標題,位於4x4網格上方的小空間中,但是當我嘗試添加標籤時,它說內容設置了多次。內容屬性不止一次設置

這裏是我的代碼:

<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> 

回答

0

Window只能包含一個孩子。在你的情況下,你的Window包含一個Grid和一個Label

確保您的Window只有一個孩子,您可以通過將Label置於Grid之內來實現此目的。像這樣:

<Window ... > 
    <Grid> 
     <Grid ...> 
      ... 
     </Grid> 

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