Got stuck up with wrap the text when user enters in the text box,used "MaxWidth to control the text box and wrap the text but it shrink the textbox size.am not sure how i have to strecth it,eventhoug am using HorizantalAlignment ="Stretch" but it doesn't match with the other text box.
If i don't wrap the text then the whole grid is moving to if the text is larger than the text box,is this anyway to fix the size and wrap the text please.
Here is my xaml code
<DockPanel Grid.Row="1">
<Grid Name="gLeftContent" Grid.Row="0" Background="Transparent" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="30" />
<RowDefinition Height="20"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0" />
<RowDefinition Height="25" />
<!-- Row 14 -->
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<TextBox
Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Width="{Binding ActualWidth, ElementName=tbName}" **//used ActualWidth but it shrinks the text box and doesn't match with the other text box.**
Grid.Column="1"
Grid.Row="5"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbSlug_LostFocus"
>
<TextBox
Name="tbHeadline"
Text="{Binding SelectedStory.Headline, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="6"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbHeadline_LostFocus"
/>
</TextBox>
<ItemsControl
Grid.Column="1"
Grid.Row="14"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.MetadataGenerateImagesRegion}"/>
</Grid>
</DockPanel>
Thanks in Advance.
Let's start again with a clean answer:
<TextBox Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Width="Auto" Height="Auto"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="2"
TextWrapping="Wrap" AcceptsReturn="True"
LostFocus="tbSlug_LostFocus" >
Please replace it entirely in your code to avoid any omision.
You need to set the RowDefinition Height="Auto" do it can grow to fit additional lines.
Definitely should not be binding width to itself.
Try
<TextBox
Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="5"
Grid.ColumnSpan="2"
TextWrapping="Wrap"
HorizontalAlignment="Stretch"
LostFocus="tbSlug_LostFocus" />
Try to add to your textbox:
AcceptsReturn="True"
Although your control may present wrapped text, currently it is unable to accept enter keystrokes.
Related
anybody got an idea why the datepicker shows the content of a nearby label? The label which is displayed is in a different grid. When I delete the Labels text and leave it blank the text of the next label of the grid is displayed and so on.
Cant figure out why this happens. Once im hovering over the datepicker with the mouse it shows the correct watermark.
[EDIT] Sorry, following a part of the code.
<StackPanel Grid.Row="1" Grid.Column="0">
<Grid Margin="10,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Beauftragt durch:"
Grid.Row="0" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="OrderedByEmp"
IsEnabled="False"
Text="{Binding OrderedByEmpName}"
Grid.Row="0" Grid.Column="1"
Width="110" Margin="10,2"
/>
<Label Content="Projekt:"
Grid.Row="1" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="Project"
MaxLength="10"
Text="{Binding Project}"
Grid.Row="1" Grid.Column="1"
Width="110" Margin="0,2"
/>
<Label Content="Auftrag:"
Grid.Row="2" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="Order" Text="{Binding Commission}"
MaxLength="8"
Grid.Row="2" Grid.Column="1"
Width="110" Margin="0,2"
/>
</Grid>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<Grid Margin="10,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Erstellt am:"
Grid.Row="0" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="OrderDate" Text="{Binding OrderDate, Mode=TwoWay,StringFormat='{}{0:dd.MM.yyyy}'}"
IsEnabled="False"
Grid.Row="0" Grid.Column="1"
Width="110" Margin="0,2"
/>
<Label Content="Benötigt bis:"
Grid.Row="1" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<DatePicker x:Name="ExpectedFinishDate"
Grid.Row="1" Grid.Column="1"
Width="110"></DatePicker>
<Label Content="Abteilung:"
Grid.Row="2" Grid.Column="0"
Width="110" Margin="10,2" />
<ComboBox x:Name="Departments" Grid.Row="2" Grid.Column="1">
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Bezeichnung}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="1">
<Grid Margin="10,10,2,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
VerticalAlignment="Center" HorizontalAlignment="Right">
FLAG:
</TextBlock>
<Image Grid.Row="0" Grid.Column="1" Height="20" Source="/Pictures/NotStartetButton.png" />
<Label Content="Fertiggestellt am:"
Grid.Row="1" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="FinishDatetime"
IsEnabled="False"
Grid.Row="1" Grid.Column="1"
Width="110" Margin="0,2"
/>
<Label Content="Fertiggestellt durch"
Grid.Row="2" Grid.Column="0"
Width="110" Margin="10,2"
HorizontalAlignment="Left" />
<TextBox x:Name="FinishedByEmp"
IsEnabled="False"
Grid.Row="2" Grid.Column="1"
Width="110" Margin="0,2"
/>
</Grid>
</StackPanel>
When I put the datepicker to another spot its working correct.
Tried now for hours to figure out why... but cant find the reason.
Thanks for any suggestion!
I've tried to reproduce the problem in another file and realized that the behavior has changed. Stupidly I left the further research on that problem since I've thought it's located anywhere in the related bindings and just went ahead to come back to that later.
But finally I made so many changes that the problem just disappeared.
I'm making an application in which i've used some controls inside Grid Panel. Its working fine but there is a problem for different screen resolution. The Grid controls cannot adapt screen resolution and clip out some control in Height. Whereas width adapt screen resolution correctly. The before and after image is under as you can see when translated into height, cause clipping problem. How to resolve this?
before translated into height:
after translated into height:
Code:
<Grid Grid.Row="3">
<Grid.Background>
<SolidColorBrush Color="#FF3E7038" Opacity="0.3"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Customer:" Grid.Column="0" Margin="10"/>
<controls:AutoCompleteBox Margin="0,10,10,0" Name="CustomerSearch" IsTextCompletionEnabled="True" SelectedItem="{Binding Name, Mode=TwoWay}" Grid.Column="1" PreviewKeyDown="CustomerSearch_PreviewKeyDown" >
<controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Code}"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Address}"/>
<TextBlock Text="{Binding Contact}"/>
</StackPanel>
</DataTemplate>
</controls:AutoCompleteBox.ItemTemplate>
</controls:AutoCompleteBox>
<TextBlock Text="Gross Amount:" Grid.Column="2" VerticalAlignment="Center" />
<TextBox Margin="5,10,0,0" Name="GrossAmount" Text="0.0" Grid.Column="3" IsReadOnly="True"/>
<TextBlock Text="Discount%:" Grid.Column="2" Grid.Row="1"/>
<TextBox Name="Discount" Text="0.0" Grid.Column="3" Grid.Row="1" PreviewTextInput="Discount_PreviewTextInput" PreviewKeyDown="Discount_PreviewKeyDown" />
<TextBlock Text="Net Pay:" Grid.Column="2" Grid.Row="2"/>
<TextBox Name="NetPay" Text="0.0" Grid.Column="3" Grid.Row="2" PreviewTextInput="Discount_PreviewTextInput" PreviewKeyDown="Discount_PreviewKeyDown" />
<TextBlock Text="Paid:" Grid.Column="2" Grid.Row="3"/>
<TextBox Name="Paid" Text="0.0" Grid.Column="3" Grid.Row="3" PreviewTextInput="Paid_PreviewTextInput" PreviewKeyDown="Paid_PreviewKeyDown"/>
<TextBlock Text="Return:" Grid.Column="2" Grid.Row="4"/>
<TextBox Name="Return" Text="0.0" Grid.Column="3" Grid.Row="4" IsReadOnly="True"/>
<WrapPanel Grid.Row="5" Margin="0,10,0,0" Grid.ColumnSpan="5" Grid.Column="2">
<Button Name="CheckoutBtn" Margin="0,0,5,0" PreviewKeyDown="CheckoutBtn_PreviewKeyDown" Click="CheckoutBtn_Click" >
<StackPanel Orientation="Horizontal">
<Image Width="40" Height="40" Stretch="Uniform" Source="/Images/checkout.png"/>
<Label Content="CHECKOUT" />
</StackPanel>
</Button>
<Button Name="CancelBtn" Margin="0,0,5,0" Click="CancelBtn_Click" >
<StackPanel Orientation="Horizontal">
<Image Width="40" Height="40" Stretch="Uniform" Source="/Images/cancel.png"/>
<Label Content="CANCEL" />
</StackPanel>
</Button>
<Button Name="SaveBtn" Click="SaveBtn_Click" Margin="0,0,5,0">
<StackPanel Orientation="Horizontal">
<Image Width="40" Height="40" Stretch="Uniform" Source="/Images/save.png"/>
<Label Content="SAVE" />
</StackPanel>
</Button>
</WrapPanel>
</Grid>
I'm having a problem with my TextBoxs not "Auto" resizing. I'm trying to create a form that behaves and looks like the Properties Editor in Visual Studio. What appears to be happening is that the third column is not expanding to fill all of the available remaining space in the grid. Image below is how my form looks on startup.
The width of the textboxs is determined by the MinWidth setting on the third ColumnDefinition statement. Also, the Width is set to "*". With any other setting, the resizing done with the GridSplitter doesn't work correctly.
<StackPanel Orientation="Vertical" VerticalAlignment="Top" x:Name="Stacker" Grid.IsSharedSizeScope="True">
<Expander x:Name="Expand" IsExpanded="True" Header="This is a test of a Second Panel" Width="{Binding Width, ElementName=Stacker}">
<Grid x:Name="EditGrid1" Margin="3" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50" SharedSizeGroup="SharedSize1" />
<ColumnDefinition Width="Auto" SharedSizeGroup="SharedSize2" />
<ColumnDefinition Width="*" MinWidth="50" x:Name="ValueCol" />
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" x:Name="ToolBoxSplitter1" Grid.Row="1" Grid.RowSpan="6" Panel.ZIndex="1" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="3"/>
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="1" Text="{x:Static lex:DoSomeThingView.Name}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="2" Text="{x:Static lex:DoSomeThingView.Address}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="3" Text="{x:Static lex:DoSomeThingView.Zip}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="4" Text="{x:Static lex:DoSomeThingView.NumberOfDoors}" TextTrimming="CharacterEllipsis" Grid.IsSharedSizeScope="True" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="5" Text="{x:Static lex:DoSomeThingView.DoubleNumber}" />
<TextBox Grid.Column="2" Grid.Row="1" x:Name="UserName1" MaxHeight="50" TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" SpellCheck.IsEnabled="True" />
<TextBox Grid.Column="2" Grid.Row="2" x:Name="Address1" />
<TextBox Grid.Column="2" Grid.Row="3" x:Name="Zip1" />
<TextBox Grid.Column="2" Grid.Row="4" x:Name="NumberOfDoors1" />
<TextBox Grid.Column="2" Grid.Row="5" x:Name="DoubleNumber1" />
</Grid>
</Expander>
</StackPanel>
Any suggestions on how to correct this?
Have a check once again of any style being set globally because your layout worked perfectly fine with me.
try overriding your textbox style by a local resource
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}"/>
</StackPanel.Resources>
I have a datagrid in a grid but the scrollviewer is not visibile even though I made it auto.
Below in my code. I can't figure out where's the problem.
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Doctor Name" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Doctor Address" Grid.Row="1" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Entry Note" Grid.Row="2" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Join Date" Grid.Row="3" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Default Discount" Grid.Row="4" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Discount Valid Till" Grid.Row="5" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Employee Name" Grid.Row="6" Grid.Column="0" Margin="5,5,0,0"/>
<Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Report Type" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<ComboBox Grid.Row="0" Grid.Column="1" Name="cmbReportType" Text="{Binding CurrentEntity.ReportType}"/>
<Button Grid.Row="0" Grid.Column="2" Name="btnAddDetail" Content="Add Details" Command="{Binding AddDetailsCommand}"/>
</Grid>
<TextBox Grid.Row="0" Grid.Column="1" Margin="5,5,0,0" Width="190" Name="txtDocName" Text="{Binding CurrentEntity.RefName}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="75" Name="txtDocAddress" Text="{Binding CurrentEntity.RefAddress}"/>
<TextBox Grid.Row="2" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="100" Name="txtEntryNote" Text="{Binding CurrentEntity.EntryNotes}"/>
<Custom:DatePicker Grid.Row="3" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpJoinDate" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DateStarted}" SelectedDateFormat="Short"/>
<TextBox Grid.Row="4" Grid.Column="1" Height="25" Width="75" Name="txtDefaultDiscount" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Top" Text="{Binding CurrentEntity.DefaultDiscount}"/>
<Custom:DatePicker Grid.Row="5" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpValidTill" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DefaultDiscountValidTill}" SelectedDateFormat="Short"/>
<ComboBox Grid.Row="6" Grid.Column="1" Margin="5,3,0,0" Width="190" Height="30" Name="cmbEmployeeName" ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedIndex="{Binding SelecteIndex}">
</ComboBox>
<Custom:DataGrid Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding XYZ}" AutoGenerateColumns="False" Name="grdTestDept">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding dep_id}" Width="40" Header="ID"/>
<Custom:DataGridTextColumn Binding="{Binding dep_name}" Width="125" Header="Name"/>
<Custom:DataGridTextColumn Binding="{Binding default_data}" Width="100" Header="Default Data"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
<Grid Grid.Row="0" Grid.Column="1" Grid.RowSpan="9">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="43"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="150"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="34*" ></RowDefinition>
<RowDefinition Height="337.88*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Name: " Grid.Row="0" Grid.Column="0" Margin="5,4,0,0" />
<cc:ValueEnabledCombo Grid.Column="1" x:Name="cmbfilEmployeeName" Width="150" Height="30" Margin="5,4,0,0" VerticalAlignment="Top" SelectedIndex="0"
ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedValuePath="EmployeeId" cc:ValueEnabledCombo.SelectionChanged="{Binding SelectionChangedCommand}">
</cc:ValueEnabledCombo>
<Button Grid.Column="2" Name="btnReport" Width="50" Content="Report" Height="28" Margin="5,4,0,0" Command="{Binding ReportCommand}" VerticalAlignment="Top" />
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
<Custom:DataGrid ItemsSource="{Binding DoctorList}" AutoGenerateColumns="False" Name="grdDoctor" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding RefName}" Width="Auto" Header="Doctor Name"/>
<Custom:DataGridTextColumn Binding="{Binding EmployeeFullName}" Width="Auto" Header="Employee Name"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
</Grid>
</Grid>
Kent Boogaart posted the answer here:
how can I enable scrollbars on the WPF Datagrid?
Put the DataGrid in a Grid, DockPanel, ContentControl or directly in the Window. A vertically-oriented StackPanel will give its children whatever vertical space they ask for - even if that means it is rendered out of view.
My note: It's probably best not to set the max height and width. Leave those alone and let WPF take care of the resizing for you.
I have a WPF form where I'm trying to make a simple input form. Two labels, two textboxes, and a "submit" button. I have the layout pretty good, the only thing that I can't get is for my "Labels" to be right aligned inside their cells. I have tried both TextAlign="Right" and HorizontialAlign="Right", that moves the text ALL the way over, overlaying my textbox, not just moving inside the cell. Below is the XAML for the window.
<Window x:Class="MyWebKeepAliveDesktop.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyWebKeepAlive Desktop - Login" WindowStyle="None" AllowsTransparency="true" Height="200" Width="400" >
<Border Background="#50FFFFFF" CornerRadius="7" BorderBrush="{StaticResource WindowFrameBrush}" BorderThickness="2,0,2,2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="{StaticResource WindowFrameBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="5,5,0,0" Margin="-1,0,-1,0" MouseLeftButtonDown="DragWindow">
<Grid>
<TextBlock Foreground="White" FontWeight="Bold" VerticalAlignment="Center" Margin="10,2,10,2"
Text="MyWebKeepAlive Desktop Login"/>
<Button Content="X" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" FontSize="7"
Width="15" Height="15" Padding="0" Command="ApplicationCommands.Close"/>
</Grid>
</Border>
<Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" />
<TextBlock Text="Username" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Password" FontWeight="Bold" Grid.Row="2" />
<TextBox Name="txtPassword" Width="150" Grid.Row="2" />
<Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2">
<TextBlock Text="Login" />
</Button>
</Grid>
</Grid>
</Border>
</Window>
Your grid only has one column as written. It will need two to support your setting of Grid.Column=1 for the text boxes. Thus, you need to add a <ColumnDefinitions> block. With the XAML the way it is now, WPF just throws both controls into the same column, hence the behavior you are seeing.
Here's what I came up with. Just learning WPF myself. As PeterAllenWebb mentioned, your main issue is you are missing the ColumnDefinitions. I also added the TextAlignment="Right" attributes to the two TextBlocks.
<Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="10" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" />
<TextBlock Text="Username" TextAlignment="Right" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Password" TextAlignment="Right" FontWeight="Bold" Grid.Row="2" />
<TextBox Name="txtPassword" Width="150" Grid.Row="2" Grid.Column="1"/>
<Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2">
<TextBlock Text="Login" />
</Button>
</Grid>