tags:

views:

46

answers:

2

I have this code for my very very basic WPF Project.

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">   

<Grid ShowGridLines="True">
    <ColumnDefinition x:Name="LeftColumn"></ColumnDefinition>
</Grid>

However, the column definition line gives me an error:

Error 1 Cannot add instance of type 'ColumnDefinition' to a collection of type 'UIElementCollection'. Only items of type 'UIElement' are allowed.

+2  A: 

you have to enclose it in a ColumnDefinitions collection.

<Grid Height="27">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
</Grid>

Adding row definitions works the same way.

Enjoy!

Alastair Pitts
I will, thanks! :D
Sergio Tapia
+2  A: 
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid ShowGridLines="True">
    <Grid.ColumnDefinitions>
    <ColumnDefinition x:Name="LeftColumn"></ColumnDefinition>
    </Grid.ColumnDefinitions>
</Grid>

I think this is what your looking for.

Anthony