Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML Property elements

Tags:

c#

xaml

For a project I am using XAML. I have devided my screen in different parts. The moment when I add a button, I get an error.

The error:

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

The code I am using for the button where the error has been found:

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

Does anyone know what the problem is and how I have to solve it?

The rest of the code:

<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>
like image 558
Klyner Avatar asked Apr 02 '14 09:04

Klyner


People also ask

What is property in XAML?

Advertisements. A dependency property is a specific type of property where the value is followed by a keen property system which is also a part of the Windows Runtime App. A class which defines a dependency property must be inherited from the DependencyObject class.

What are attached properties?

An attached property is a Extensible Application Markup Language (XAML) concept. Attached properties enable extra property/value pairs to be set on any XAML element that derives from DependencyObject, even though the element doesn't define those extra properties in its object model.

What is XAML code?

Extensible Application Markup Language (XAML /ˈzæməl/ ( listen)) is a declarative XML-based language that Microsoft developed for initializing structured values and objects.

What is StackPanel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.


1 Answers

You've defined an image in the grid before the grid properties. Move this to after the row and column definitions.

like image 72
Lee Willis Avatar answered Sep 20 '22 21:09

Lee Willis