2014-04-02 52 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上面的列/行定义但哟你无法把它分解