Krigga Krigga - 1 year ago 68
C# Question

Contents of grid are in wrong column

I have this XAML:

<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ListView Grid.Column="1" x:Name="layers" Grid.ColumnSpan="1">
<Image Source="{Binding}" Height="100" Width="100" Margin="5"/>
<StackPanel Grid.Column="2" Grid.ColumnSpan="2">
<Button Height="20" Content="Add layer" Click="aL_Click" HorizontalAlignment="Stretch" Width="Auto"/>
<Button Height="20" Content="Add static layer" Click="aSL_Click" HorizontalAlignment="Stretch" Width="Auto"/>

As you can see, ListView is in column 1 of Grid and the StackPanel is in column 2 of Grid. But when I run this and add Image to ListView, the ListView (and Image) are showing in column 2 of Grid, after StackPanel.

What is wrong and how do I fix it?

Answer Source

First column is column "0" and not "1". There is no sense for expression Grid.ColumnSpan="1" because it is default value as well as Grid.Column="0".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download