Problems with ScrollViewer , WPF - wpf

Bars move, but the content does not scroll.
Any ideas?
I want to create a work schedule
<Window x:Class="WpfMiGantt.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" xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon">
<Grid ShowGridLines="True">
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" >
<Border Width="1000" Height="1000"/>
</ScrollViewer >
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" ShowGridLines="True" >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="60" />
<ColumnDefinition Width="60" />
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<my:RibbonTextBox Height="23" Label="6:00" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox0" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="6:30" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox1" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="7:00" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox2" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="7:30" Grid.Column="3" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox3" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="8:00" Grid.Column="4" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox4" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="8:30" Grid.Column="5" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox5" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="9:00" Grid.Column="6" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox6" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="10:00" Grid.Column="7" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox7" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="10:30" Grid.Column="8" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox8" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="11:00" Grid.Column="9" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox9" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="11:30" Grid.Column="10" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox10" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="12:00" Grid.Column="11" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox11" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="12:30" Grid.Column="12" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox12" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="13:00" Grid.Column="13" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox13" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="13:30" Grid.Column="14" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox14" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="14:00" Grid.Column="15" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox15" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="14:30" Grid.Column="16" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox16" VerticalAlignment="Center" />
<my:RibbonTextBox Height="23" Label="15:00" Grid.Column="17" Grid.Row="0" HorizontalAlignment="Left" Margin="0" Name="ribbonTextBox17" VerticalAlignment="Center" />
</Grid>
<my:RibbonButton Label="Fecha" Grid.Column="0" Grid.Row="0" Content="Button" Height="30" HorizontalAlignment="Center" Margin="0" Name="ribbonButton0" VerticalAlignment="Center" Width="Auto" />
<my:RibbonButton Label="" Grid.Column="0" Grid.Row="1" Content="Button" Height="30" HorizontalAlignment="Center" Margin="0" Name="ribbonButton1" VerticalAlignment="Top" Width="75" />
<my:RibbonButton Content="Button" Grid.Column="2" Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Left" Margin="38,8,0,0" Name="ribbonButton2" VerticalAlignment="Top" Width="75" />
</Grid>
</Grid>
</Window>
I think the order of the lines is the key.
PD: Have you seen any similar project in codeplex or with WPF? 4

I suspect you want the scroll bars to act on the Grid. You will have to have the Grid in the ScrollViewer in that case
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" >
<Grid ShowGridLines="True" Width="1000" Height="1000">
...rest of grid content
</Grid>
</ScrollViewer >

Related

Bind button command in listboxItem

I want to bind a button command from a listbox item. But my code not work. Can you help me?
My item template definition:
<UserControl.Resources>
<DataTemplate x:Key="MemberList">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Source="{DynamicResource appbar_user}" Height="30" Width="30" VerticalAlignment="Center" HorizontalAlignment="Left"/
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding EMail}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<Button Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" Width="25" Height="25" VerticalAlignment="Center" IsDefault="False" Content="X">
</Button>
</Grid>
</DataTemplate>
</UserControl.Resources>
And my listbox declaration:
<ListBox Margin="0,0,10,0" Grid.Column="0" Grid.Row="2" x:Name="_ownersList" ItemsSource="{Binding GroupOwners}" ItemTemplate="{DynamicResource MemberList}" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="Button.Click" Handler="Button_Click"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Thank you for your help.
It worked fine for me
XAML:
<Window.Resources>
<DataTemplate x:Key="MemberList">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Source="{DynamicResource appbar_user}" Height="30" Width="30" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding EMail}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<Button Grid.Column="2" Command="{Binding DataContext.CloseButton,RelativeSource={RelativeSource AncestorType=Window, AncestorLevel=1}}" Grid.Row="0" Grid.RowSpan="2" Width="25" Height="25" VerticalAlignment="Center" IsDefault="False" Content="X">
</Button>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid Height="200" Width="200" VerticalAlignment="Center">
<ListBox Margin="0,0,10,0" Grid.Column="0" Grid.Row="2" x:Name="_ownersList" ItemsSource="{Binding GroupOwners}" ItemTemplate="{DynamicResource MemberList}" >
<!--<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="Button.Click" Handler="Button_Click"/>
</Style>
</ListBox.ItemContainerStyle>-->
</ListBox>
</Grid>
ViewModel
private ICommand closeButton;
public ICommand CloseButton
{
get
{
if (this.closeButton == null)
{
this.closeButton = new RelayCommand<object>(this.ExecuteCloseButton);
}
return this.closeButton;
}
}
private void ExecuteCloseButton(object err)
{
}

Gridsplitter does not allow user to resize grid

My code is as follows:
<Grid
ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<GridSplitter
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Width="5"
Background="Purple"
HorizontalAlignment="left" />
<ListBox
Grid.Row="0"
Grid.Column="0"
ItemsSource="{Binding Tests}"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
Grid.IsSharedSizeScope="True">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="10*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock
Text="{Binding Name}"
Grid.Column="0">
</TextBlock>
<Image
Grid.Column="1">
</Image>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Text="{Binding CommandPromptOutput}">
</TextBlock>
<Button
Grid.Row="1"
Grid.Column="2"
Content="Run" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch" />
</Grid>
The grid splitter is showing up but it has no control over resizing anything.
I have also tried adding:
<GridSplitter
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Width="5"
Background="Purple"
HorizontalAlignment="left"
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext" />

Difficulties to use columnspan

I have grid with four texboxs like these :
And I would to get this:
I have tried to play with column span but with no success :(
<Grid Margin="20,0,0,20" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="1" Grid.Row="0" Grid.Column="0" Margin="0,0,10,0" x:Name="TxtBox_CodeTiers" TextWrapping="Wrap" Text="{Binding m_strCode}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23"/>
<TextBlock Grid.ColumnSpan="1" Grid.Row="0" Grid.Column="1" Margin="0,0,10,0" x:Name="TxtBox_NomTiers" TextWrapping="Wrap" Text="{Binding m_strNom}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,05,0" x:Name="TxtBox_CPostal" TextWrapping="Wrap" Text="{Binding m_strCpostal}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,0,05,0" x:Name="TxtBox_Ville" TextWrapping="Wrap" Text="{Binding m_strVille}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}"/>
</Grid>
It better with this :)
<Grid Margin="12,0,0,20" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" x:Name="TxtBox_CodeTiers" Margin="0,0,20,0" TextWrapping="Wrap" Text="{Binding m_strCode}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23" Loaded="TxtBlock_Loaded"/>
<TextBlock Grid.Row="0" Grid.Column="2" x:Name="TxtBox_NomTiers" TextWrapping="Wrap" Text="{Binding m_strNom}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23" Loaded="TxtBlock_Loaded"/>
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="TxtBox_CPostal" Margin="0,0,20,0" TextWrapping="Wrap" Text="{Binding m_strCpostal}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}" Loaded="TxtBlock_Loaded"/>
<TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" x:Name="TxtBox_Ville" TextWrapping="Wrap" Text="{Binding m_strVille}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}" Loaded="TxtBlock_Loaded"/>
</Grid>
You will probably need to add another column for the "C" and "D" boxes to line up against, then just set the ColumnSpan on the "A" box to span the new column
<Grid Margin="20,0,0,20" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="121*"/>
<ColumnDefinition Width="52*"/>
<ColumnDefinition Width="190*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" x:Name="TxtBox_CodeTiers" TextWrapping="Wrap" Text="AAAAAAAAA" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23"/>
<TextBlock Grid.Row="0" Grid.Column="2" x:Name="TxtBox_NomTiers" TextWrapping="Wrap" Text="BBBBBBBB" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23" />
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="TxtBox_CPostal" TextWrapping="Wrap" Text="CCCCCCCCCCC" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" x:Name="TxtBox_Ville" TextWrapping="Wrap" Text="DDDDDDDDD" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}" />
</Grid>
You can use in the second grid row StackPanel:
<Grid Margin="20,0,0,20" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="1" Grid.Row="0" Grid.Column="0" Margin="0,0,10,0" x:Name="TxtBox_CodeTiers" TextWrapping="Wrap" Text="{Binding m_strCode}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23"/>
<TextBlock Grid.ColumnSpan="1" Grid.Row="0" Grid.Column="1" Margin="0,0,10,0" x:Name="TxtBox_NomTiers" TextWrapping="Wrap" Text="{Binding m_strNom}" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="23" />
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2">
<TextBlock Margin="0,0,05,0" x:Name="TxtBox_CPostal" TextWrapping="Wrap" Text="{Binding m_strCpostal}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}"/>
<TextBlock Margin="0,0,05,0" x:Name="TxtBox_Ville" TextWrapping="Wrap" Text="{Binding m_strVille}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="{StaticResource PhoneDisabledBrush}"/>
</StackPanel>
</Grid>

what can i do with that scrollviewer?

i used a GroupBox with a scrollviewer inside it ..and inside scrollviewer i put a grid and begin to put my controls (3 textblocks and 7 textboxes)
i can't make scrollviewer to scroll my content ..and i don't know if i miss something to activate it
here is my xaml code:
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="363,20,38,486" Name="groupBox1" VerticalAlignment="Stretch" Panel.ZIndex="0">
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
<Grid Name="grid1" Height="132">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
</Grid>
</ScrollViewer>
</GroupBox>
Try setting your GroupBox's Height. It is stretching to fill the entire Window and your content is stretching to Fit. If you limit the size of the GroupBox you will get your VerticalScroll and it will work. I modified your code to this and it works:
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Height="132" Name="groupBox1" Panel.ZIndex="0">
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
<Grid Name="grid1" Height="132">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
</Grid>
</ScrollViewer>
</GroupBox>
With the result of this:
I modified your code a bit
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="1,0,0,129" Name="groupBox1" VerticalAlignment="Stretch" Grid.Column="1" Grid.RowSpan="3">
<ScrollViewer Name="scrollViewer1" Width="Auto" VerticalScrollBarVisibility="Visible" >
<Grid Name="grid1" Width="376" Height="280">
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock4" Padding="0" Text="Generic ID" TextAlignment="Right" Margin="-20,0,20,0" />
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock5" Padding="0" Text="Generic Name" TextAlignment="Right" Margin="-10,20,10,-20" />
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock6" Padding="0" Text="Other Names" TextAlignment="Right" Margin="-15,43,15,-43" />
<TextBox Height="25" Name="textBox8" Width="225" Margin="22,199,130,44" />
<TextBox Height="25" Name="textBox9" Width="225" Margin="20,147,131,95" />
<TextBox Height="25" Name="textBox11" Width="225" Margin="20,97,131,159" />
<TextBox Height="25" Name="textBox12" Margin="21,122,131,121" />
<TextBox Height="25" Name="textBox13" Width="225" Margin="20,159,131,52" />
<TextBox Height="25" Name="textBox14" Width="225" Margin="20,222,131,20" />
</Grid>
</ScrollViewer>
</GroupBox>
</Grid>
Just try whether this works out.I think the margin and height are resulting in the problem

WPF Alignment problems

I have this window:
My problem is that when the number is larger than 2 digits, it pushes the red rectangle to
the right. and I would like it to act like that:
The rectangle must not been pushed to the right.
This is my XAML:
<StackPanel>
<Border BorderThickness="1" BorderBrush="Beige">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="1">
<TextBlock Text="1" VerticalAlignment="Top" />
<Rectangle Width="20" Height="20" Fill="Red" VerticalAlignment="Top" />
</StackPanel>
</Grid>
</Border>
<Border BorderThickness="1" BorderBrush="Beige">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="1" >
<TextBlock Text="1123" VerticalAlignment="Top" />
<Rectangle Width="20" Height="20" Fill="Red" VerticalAlignment="Top" />
</StackPanel>
</Grid>
</Border>
</StackPanel>
<StackPanel>
<Border BorderThickness="1" BorderBrush="Beige">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="1" VerticalAlignment="Top" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>
<Rectangle Width="20" Height="20" Fill="Red" Grid.Column="1" Grid.Row="0"/>
<TextBlock Text="1123" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right"/>
<Rectangle Width="20" Height="20" Fill="Red" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Border>
</StackPanel>

Resources