2014-04-02 50 views
5

對於我使用XAML的項目。我已將屏幕劃分爲不同的部分。當我添加一個按鈕的時候,我收到一個錯誤。XAML特性元素

錯誤:

'property elements cannot be in the middle of an element's content'

我使用的按鈕,其誤差已發現代碼:

<Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

有誰知道問題是什麼,我怎麼也得解決它?

的其餘代碼:

<Window x:Class="Pesten.View.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> 
    <Image Grid.RowSpan="4" Grid.ColumnSpan="3" Stretch="Fill" Source="pestenbg.jpg" VerticalAlignment="Top" HorizontalAlignment="Center"/> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="4*"/> 
     <ColumnDefinition Width="2*"/> 
     <ColumnDefinition Width="4*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="5*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="2*"/> 
    </Grid.RowDefinitions> 

    <Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

</Grid> 

</Window> 
+4

,你能否告訴XAML文件的休息嗎? – BenjaminPaul

+0

Button元素本身看起來不錯。你可以發佈更多的XAML嗎?也許整個呢?的 –

+0

可能重複[WPF錯誤:屬性元素不能在元素內容的中間。他們必須在內容之前或之後](http://stackoverflow.com/questions/26524787/wpf-error-property-elements-cannot-be-in-the-middle-of-an-elements-content-th) – Dzyann

回答

6

你在網格屬性前格柵定義的圖像。將其移至行和列定義之後。

+1

謝謝!愚蠢的錯誤...... – Klyner

+0

很高興提供幫助。打勾接受答案,然後我們都很高興:-) –

+0

我將不得不等待5分鐘的延遲。 – Klyner

0

開幕標籤後直接把列和行定義。所有的內容都應該遵循那個(即the和the)。

1

您要添加Button控制在錯誤的地方父控件:

Property elements cannot be in the middle of an element's content

Property elements cannot be in the middle of an element's content. They must be before or after the content. This error is occurs when you attempt to use property-element syntax within an element's content.

移動ImageColumnDefinitions之後和之前Button

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="4*"/> 
     <ColumnDefinition Width="2*"/> 
     <ColumnDefinition Width="4*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="5*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="2*"/> 
    </Grid.RowDefinitions> 

    <Image Grid.RowSpan="4" Grid.ColumnSpan="3" Stretch="Fill" Source="pestenbg.jpg" VerticalAlignment="Top" HorizontalAlignment="Center"/> 
    <Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

</Grid> 

或移動這兩個ImageButton上面的列/行定義但喲你無法把它分解