19

I've been through this site (and many others) trying to figure out what is going on and why this does not work. I am running VS2012 and have created a WPF C# app (target .NET 4.5). I am new to WPF, having spent many years coding Windows Forms apps, but decided to take the plunge, and am liking XAML so far.

Ultimately I want to: 1) Remove a user control in a particular Row (RowDefinition) in my Grid 2) Place another user control in that particular Row

However I can't seem to place even a simple button control. What I want to do is place a button in Row 4 (3 with zero index). Here is my XAML:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Custom="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" x:Class="TestApp2_WindowsClient.MainWindow" Title="Test App 2" Height="700" Width="1000" MinHeight="700" MinWidth="1000" MaxHeight="700" MaxWidth="1000" FontSize="12" FontFamily="Segoe UI Semibold"> <Grid VerticalAlignment="Top" Name="gridMain"> <Grid.RowDefinitions> <RowDefinition Height="60"/> <RowDefinition Height="152"/> <RowDefinition Height="240"/> <RowDefinition Height="60"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="0"/> </Grid.ColumnDefinitions> <StackPanel Name="stackButtons1" HorizontalAlignment="Left" Height="50" Margin="4,4,-310,4" Grid.Row="0" VerticalAlignment="Top" Width="300" Orientation="Horizontal" > <Button Content="Show Bookings" Height="24" Margin="4,0,0,0" Click="Button_Click_1" /> <Button Content="Show Radio Buttons" Height="24" Margin="4,0,0,0" Click="Button_Click_2" /> </StackPanel> </Grid> </Window> 

The button code (first button in Stack Panel) is:

Button MyControl = new Button(); MyControl.Content = "Test Button!"; Grid.SetRow(MyControl, 3); Grid.SetColumn(MyControl, 0); gridMain.Children.Add(MyControl); 

I can see (in my watch) that the gridMain.Children count value increases every time I click the first button, but nothing appears on the screen.

It's probably something really silly, but a few hours of searching and trying a stack of different code has not helped.

Thanks in advance!

1
  • 1
    While nothing to do with the answer to the question, this question did solve the issue I was stuck on (I was looking for Grid.SetRow, Grid.SetColumn, and <gridName>.Children.Add). Thanks for that! Commented Mar 14, 2014 at 14:32

1 Answer 1

26
<ColumnDefinition Width="0"/> 

Maybe you could see the button if you increased the width.

Sign up to request clarification or add additional context in comments.

1 Comment

Worth noting that these issues can often be diagnosed by using Snoop

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.