user control numeric pad - wpf

i had made a user control numeric pad in wpf. i want to know when i placed a control over the form. when i pressed any numeric button then it should be entered in the focused area. how to do it
this is my xaml script
enter code here
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Name="btn2" Content="2" Focusable="False" FontSize="26" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row=" 1" />
<Button Name="btn1" Content="1" Focusable="False" FontSize="26" HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Stretch" BorderBrush="DarkGray" BorderThickness="4,2,2,8" />
<Button Name="btn3" Content="3" Focusable="False" FontSize="26" Grid.Column="2" Foreground="White" HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Stretch" />
<Button Name="btn4" Content="4" Focusable="False" FontSize="26" HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Stretch" />
<Button Name="btn5" Content="5" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Stretch" />
<Button Name="btn6" Content="6" Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Stretch" />
<Button Name="btn7" Content="7" Focusable="False" FontSize="26" HorizontalAlignment="Stretch" Grid.Row="3" VerticalAlignment="Stretch" />
<Button Name="btn8" Content="8" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="3" VerticalAlignment="Stretch" />
<Button Name="btn9" Content="9" Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch" Grid.Row="3" VerticalAlignment="Stretch" />
<Button Name="btn0" Content="0" Focusable="False" FontSize="26" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" />
<Button Name="btn00" Content="00" Focusable="False" FontSize="26" Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" />
<Button Name="btn_dot" Content="." Focusable="False" FontSize="26" Grid.Column="2" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" />
<Button Name="btn_temp1" Content="Button" Focusable="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Name="btn_temp2" Content="Button" Focusable="False" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Name="btn_temp3" Content="Button" Focusable="False" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
``

You should attach an event handler to the UIElement.PreviewKeyDown Event to handle key presses in WPF in your UserControl constructor, or Loaded event handler:
PreviewKeyDown += YourKeyEventHandler;
...
private void YourKeyEventHandler(object sender, KeyEventArgs e)
{
// Do something here with e.Key (the pressed key)
}
You can find out more from the linked page on MSDN.

Related

Overlap Buttons on a Xaml Grid on Powershell with onclick button

New to Powershell, Xaml and coding in general.
Thanks to StackOverflow, I've build a Grid in Powershell with 10 Columns and 8 Rows and fill it with 80 Buttons (From 1 to 80). Each button will trigger an action.
Now, I would like to have the chance to Click on 1 of these buttons and overlap new buttons (or a whole new Grid) on top of the principal Grid in orther to have more buttons available (From 81 to 160).
To make a clear example:
Let's imagine I'm building an App to make orders in the restaurant.
Grid 1 Show 80 buttons.
If I press the "Main Course" button, it will overlay the 80 buttons containing the 80 differents "Main Course". The same if I press "Dessert" buttons ect.
I understood to use the expression Panel.ZIndex="n" and actually work if I code it in Powershell.
<Button Name="Cell2" Grid.Row="0" Grid.Column="1" Opacity="1" Background="#eae0f5" FontFamily="Impact" FontSize="25" Foreground="White" Content="UP" Panel.ZIndex="1"/>
<Button Name="Cell81" Grid.Row="0" Grid.Column="1" Opacity="1" Background="#dfd1f0" FontFamily="Impact" FontSize="25" Foreground="White" Content="DOWN" Panel.ZIndex="0"/>
But when I want to trigger it with a click button like so:
$WPFCell1.add_Click({$WPFCell81.Panel.ZIndex ="2"})
it returns with the following error:
The property 'ZIndex' cannot be found on this object. Verify that the property exists and can be set.
At line:149 char:22
+ $WPFCell1.add_Click({$WPFCell81.Panel.ZIndex ="2"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Where should I add the Porperty ZIndex if this is the error?
I know probably there are different way to setup this things, but I would like to find a way to make it happen with this code couse again, I'm a noob, and I'm working with a Library that work with this kind of code.
Many thanks to all of you!
This is the whole code if can halp:
#MultiView click overlay
$inputXML = #"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
WindowStyle = "None" WindowState="Maximized"
ResizeMode = "NoResize" Title = "overlay" AllowsTransparency = "True" Background = "Transparent" Opacity = "1" Topmost = "True">
<Grid x:Name = "Grid" Background = "Transparent" ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="96" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="55" />
<RowDefinition Height="190" />
<RowDefinition Height="190" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="55" />
</Grid.RowDefinitions>
<Button Name="Cell1" Grid.Row="0" Grid.Column="0" Opacity="1" Background="#eae0f5" FontFamily="Impact" FontSize="25" Foreground="White" Content="MENU"/>
<Button Name="Cell2" Grid.Row="0" Grid.Column="1" Opacity="1" Background="#dfd1f0" FontFamily="Impact" FontSize="25" Foreground="White" Content="UP" Panel.ZIndex ="1"/>
<Button Name="Cell3" Grid.Row="0" Grid.Column="2" Opacity="1" Background="#d4c1eb" FontFamily="Impact" FontSize="25" Foreground="White" Content="3"/>
<Button Name="Cell4" Grid.Row="0" Grid.Column="3" Opacity="1" Background="#c9b2e6" FontFamily="Impact" FontSize="25" Foreground="White" Content="4"/>
<Button Name="Cell5" Grid.Row="0" Grid.Column="4" Opacity="1" Background="#bfa3e1" FontFamily="Impact" FontSize="25" Foreground="White" Content="4"/>
<Button Name="Cell6" Grid.Row="0" Grid.Column="5" Opacity="1" Background="#b493dc" FontFamily="Impact" FontSize="25" Foreground="White" Content="5"/>
<Button Name="Cell7" Grid.Row="0" Grid.Column="6" Opacity="1" Background="#a984d7" FontFamily="Impact" FontSize="25" Foreground="White" Content="6"/>
<Button Name="Cell8" Grid.Row="0" Grid.Column="7" Opacity="1" Background="#9f74d2" FontFamily="Impact" FontSize="25" Foreground="White" Content="7"/>
<Button Name="Cell9" Grid.Row="0" Grid.Column="8" Opacity="1" Background="#9465cd" FontFamily="Impact" FontSize="25" Foreground="White" Content="8"/>
<Button Name="Cell10" Grid.Row="0" Grid.Column="9" Background="#f75590" FontFamily="Impact" FontSize="25" Foreground="White" Content="9" />
<Button Name="Cell11" Grid.Row="1" Grid.Column="0" Opacity="1" Background="#dfd1f0" FontFamily="Impact" FontSize="25" Foreground="White" Content="10"/>
<Button Name="Cell12" Grid.Row="1" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell13" Grid.Row="1" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell14" Grid.Row="1" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell15" Grid.Row="1" Grid.Column="4" Opacity="1" Background="#8956c8" FontFamily="Impact" FontSize="25" Foreground="White" Content="14"/>
<Button Name="Cell16" Grid.Row="1" Grid.Column="5" Opacity="1" Background="Yellow" FontFamily="Impact" FontSize="25" Foreground="White" Content="15"/>
<Button Name="Cell17" Grid.Row="1" Grid.Column="6" Opacity="0.01"/>
<Button Name="Cell18" Grid.Row="1" Grid.Column="7" Opacity="0.01"/>
<Button Name="Cell19" Grid.Row="1" Grid.Column="8" Opacity="0.01"/>
<Button Name="Cell20" Grid.Row="1" Grid.Column="9" Opacity="1" Background="#8956c8" FontFamily="Impact" FontSize="25" Foreground="White" Content="20"/>
<Button Name="Cell21" Grid.Row="2" Grid.Column="0" Opacity="1" Background="#cae916" FontFamily="Impact" FontSize="28" Foreground="White" Content="21"/>
<Button Name="Cell22" Grid.Row="2" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell23" Grid.Row="2" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell24" Grid.Row="2" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell25" Grid.Row="2" Grid.Column="4" Opacity="0.01"/>
<Button Name="Cell26" Grid.Row="2" Grid.Column="5" Opacity="0.01"/>
<Button Name="Cell27" Grid.Row="2" Grid.Column="6" Opacity="0.01"/>
<Button Name="Cell28" Grid.Row="2" Grid.Column="7" Opacity="0.01"/>
<Button Name="Cell29" Grid.Row="2" Grid.Column="8" Opacity="0.01"/>
<Button Name="Cell30" Grid.Row="2" Grid.Column="9" Opacity="1" Background="#cae916" FontFamily="Impact" FontSize="28" Foreground="White" Content="30"/>
<Button Name="Cell31" Grid.Row="3" Grid.Column="0" Opacity="1" Background="#c9b2e6" FontFamily="Impact" FontSize="30" Foreground="White" Content="31"/>
<Button Name="Cell32" Grid.Row="3" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell33" Grid.Row="3" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell34" Grid.Row="3" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell35" Grid.Row="3" Grid.Column="4" Opacity="0.01"/>
<Button Name="Cell36" Grid.Row="3" Grid.Column="5" Opacity="0.01"/>
<Button Name="Cell37" Grid.Row="3" Grid.Column="6" Opacity="0.01"/>
<Button Name="Cell38" Grid.Row="3" Grid.Column="7" Opacity="0.01"/>
<Button Name="Cell39" Grid.Row="3" Grid.Column="8" Opacity="0.01"/>
<Button Name="Cell40" Grid.Row="3" Grid.Column="9" Opacity="1" Background="#6a37a9" FontFamily="Impact" FontSize="30" Foreground="White" Content="40"/>
<Button Name="Cell41" Grid.Row="4" Grid.Column="0" Opacity="1" Background="#bfa3e1" FontFamily="Impact" FontSize="30" Foreground="White" Content="41"/>
<Button Name="Cell42" Grid.Row="4" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell43" Grid.Row="4" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell44" Grid.Row="4" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell45" Grid.Row="4" Grid.Column="4" Opacity="0.01"/>
<Button Name="Cell46" Grid.Row="4" Grid.Column="5" Opacity="0.01"/>
<Button Name="Cell47" Grid.Row="4" Grid.Column="6" Opacity="0.01"/>
<Button Name="Cell48" Grid.Row="4" Grid.Column="7" Opacity="0.25" Background="#0000ffff" FontFamily="Impact" FontSize="20" Foreground="White" Content="48"/>
<Button Name="Cell49" Grid.Row="4" Grid.Column="8" Opacity="0.25" Background="#0000ffff" FontFamily="Impact" FontSize="20" Foreground="White" Content="49"/>
<Button Name="Cell50" Grid.Row="4" Grid.Column="9" Opacity="1" Background="#61329a" FontFamily="Impact" FontSize="25" Foreground="White" Content="50"/>
<Button Name="Cell51" Grid.Row="5" Grid.Column="0" Opacity="1" Background="#b493dc" FontFamily="Impact" FontSize="30" Foreground="White" Content="51"/>
<Button Name="Cell52" Grid.Row="5" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell53" Grid.Row="5" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell54" Grid.Row="5" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell55" Grid.Row="5" Grid.Column="4" Opacity="0.01"/>
<Button Name="Cell56" Grid.Row="5" Grid.Column="5" Opacity="1" Background="#a984d7" FontFamily="Impact" FontSize="28" Foreground="White" Content="56"/>
<Button Name="Cell57" Grid.Row="5" Grid.Column="6" Opacity="1" Background="#9f74d2" FontFamily="Impact" FontSize="25" Foreground="White" Content="57"/>
<Button Name="Cell58" Grid.Row="5" Grid.Column="7" Opacity="1" Background="#cae916" FontFamily="Impact" FontSize="35" Foreground="White" Content="58"/>
<Button Name="Cell59" Grid.Row="5" Grid.Column="8" Opacity="1" Background="#f75590" FontFamily="Impact" FontSize="30" Foreground="White" Content="59"/>
<Button Name="Cell60" Grid.Row="5" Grid.Column="9" Opacity="1" Background="#4d287b" FontFamily="Impact" FontSize="20" Foreground="White" Content="60"/>
<Button Name="Cell61" Grid.Row="6" Grid.Column="0" Opacity="1" Background="#cae916" FontFamily="Impact" FontSize="60" Foreground="White" Content="61"/>
<Button Name="Cell62" Grid.Row="6" Grid.Column="1" Opacity="0.01"/>
<Button Name="Cell63" Grid.Row="6" Grid.Column="2" Opacity="0.01"/>
<Button Name="Cell64" Grid.Row="6" Grid.Column="3" Opacity="0.01"/>
<Button Name="Cell65" Grid.Row="6" Grid.Column="4" Opacity="0.01"/>
<Button Name="Cell66" Grid.Row="6" Grid.Column="5" Opacity="1" Background="#bfa3e1" FontFamily="Impact" FontSize="25" Foreground="White" Content="66"/>
<Button Name="Cell67" Grid.Row="6" Grid.Column="6" Opacity="1" Background="#a984d7" FontFamily="Impact" FontSize="25" Foreground="White" Content="67"/>
<Button Name="Cell68" Grid.Row="6" Grid.Column="7" Opacity="1" Background="#9465cd" FontFamily="Impact" FontSize="25" Foreground="White" Content="68"/>
<Button Name="Cell69" Grid.Row="6" Grid.Column="8" Opacity="1" Background="#a984d7" FontFamily="Impact" FontSize="30" Foreground="White" Content="69"/>
<Button Name="Cell70" Grid.Row="6" Grid.Column="9" Opacity="1" Background="#cae916" FontFamily="Impact" FontSize="45" Foreground="White" Content="70"/>
<Button Name="Cell71" Grid.Row="7" Grid.Column="0" Opacity="1" Background="#9f74d2" FontFamily="Impact" FontSize="25" Foreground="White" Content="71"/>
<Button Name="Cell72" Grid.Row="7" Grid.Column="1" Opacity="1" Background="#9465cd" FontFamily="Impact" FontSize="25" Foreground="White" Content="72"/>
<Button Name="Cell73" Grid.Row="7" Grid.Column="2" Opacity="1" Background="#8956c8" FontFamily="Impact" FontSize="25" Foreground="White" Content="73"/>
<Button Name="Cell74" Grid.Row="7" Grid.Column="3" Opacity="1" Background="#773dbd" FontFamily="Impact" FontSize="25" Foreground="White" Content="74"/>
<Button Name="Cell75" Grid.Row="7" Grid.Column="4" Opacity="1" Background="#6a37a9" FontFamily="Impact" FontSize="25" Foreground="White" Content="75"/>
<Button Name="Cell76" Grid.Row="7" Grid.Column="5" Opacity="1" Background="#61329a" FontFamily="Impact" FontSize="25" Foreground="White" Content="76"/>
<Button Name="Cell77" Grid.Row="7" Grid.Column="6" Opacity="1" Background="#4d287b" FontFamily="Impact" FontSize="25" Foreground="White" Content="77"/>
<Button Name="Cell78" Grid.Row="7" Grid.Column="7" Opacity="1" Background="#44236c" FontFamily="Impact" FontSize="25" Foreground="White" Content="78"/>
<Button Name="Cell79" Grid.Row="7" Grid.Column="8" Opacity="1" Background="#3a1e5c" FontFamily="Impact" FontSize="25" Foreground="White" Content="79"/>
<Button Name="Cell80" Grid.Row="7" Grid.Column="9" Opacity="1" Background="#30194d" FontFamily="Impact" FontSize="25" Foreground="White" Content="80"/>
<Button Name="Cell81" Grid.Row="0" Grid.Column="1" Opacity="1" Background="#8956c8" FontFamily="Impact" FontSize="25" Foreground="White" Content="DOWN" Panel.ZIndex ="0"/>
</Grid>
</Window>
"#
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Window=[Windows.Markup.XamlReader]::Load( $reader )}
catch [System.Management.Automation.MethodInvocationException] {
Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..."
write-host $error[0].Exception.Message -ForegroundColor Red
if ($error[0].Exception.Message -like "*button*"){
write-warning "Ensure your <button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n"}
}
catch{#if it broke some other way :D
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
}
# Create PowerShell object for each WPF button
$xaml.SelectNodes("//*[#Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Window.FindName($_.Name)}
# Map multiview window click to actual
function buttonclicked($btnNAme){
write-host $btnNAme
switch($btnNAme){
0{$Script:Window.close();break
}
}
}
$WPFCell1.add_Click({$WPFCell16.Panel.ZIndex ="1"})
# Turn on WPF overlay display
$Window.ShowDialog() | out-null
Just found a workaround to get the same results with .Visibility "Hidden" or "Visible".
Same structure, same use of Panel.Zindex="n" but instead of modifying the ZIndex value with the button, I hide or show the layer on top.
But I'm sure there is a more convinient way to act, so if you have the solution, pleaseeee :).
Cheers,
M

Perform calculation in TexBox from values in 2 Texboxes binded do sliders

I have this code:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="300*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label x:Name="labelMultiplicador" Grid.Row="0" Grid.Column="0" Content="Multiplicador:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<Slider x:Name="sliderMultiplicador" Grid.Row="0" Grid.Column="1" Orientation="Horizontal" SmallChange="1" IsSnapToTickEnabled="True" Minimum="1" VerticalAlignment="Center" Height="1" MinHeight="30" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" MinWidth="300" Margin="5" TickPlacement="TopLeft" />
<TextBox x:Name="textBoxMultiplicador" Grid.Row="0" Grid.Column="2" Width="50" Text="{Binding ElementName=sliderMultiplicador,Path=Value}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MinHeight="30" />
<Label x:Name="labelMultiplicando" Grid.Row="1" Grid.Column="0" Content="Multiplicando:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<Slider x:Name="sliderMultiplicando" Grid.Row="1" Grid.Column="1" Orientation="Horizontal" SmallChange="1" IsSnapToTickEnabled="True" Minimum="1" VerticalAlignment="Center" MinHeight="30" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" MinWidth="300" Margin="5" Height="1" TickPlacement="TopLeft" />
<TextBox x:Name="textBoxMultiplicando" Grid.Row="1" Grid.Column="2" Width="50" Text="{Binding ElementName=sliderMultiplicando,Path=Value}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MinHeight="30" />
<Label x:Name="labelProduto" Grid.Row="2" Grid.Column="0" Content="Produto:" FontWeight="Bold" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" />
<TextBox x:Name="textBoxProduto" Grid.Row="2" Grid.Column="2" Width="50" Text="" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="1,0,0,0" Margin="5" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" MinHeight="30" />
</Grid>
I want to calculate the product (textBoxProduto) using the values from textBoxMultiplicador and textBoxMultiplicando.
I'm new to WPF so this might be a "stupid" question!!!
If i try to calculate the product using the textBoxMultiplicador_TextChanged event, for example, e get a "'System.NullReferenceException'".
What is the best approach in this case?
Thanks
Full example here: https://www.dropbox.com/s/e8w9t59vjhnqjbb/tabuada.zip?dl=0

Responsive wpf Window

I am new with WPF please keep that in mind. I am trying to Make the Window Responsive to Resize, Is it possible that my controls such as textboxes and buttons are Resized as window grows or shrinks?
<Window x:Class="WPF_Working_Experimenet.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="216.586" Width="459.256">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="156*"/>
<ColumnDefinition Width="295*"/>
</Grid.ColumnDefinitions>
<Label Content="username :" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="66,27,0,0" Height="30" Width="63" FontFamily="B Nazanin" FontSize="15" Grid.Column="1"/>
<Label Content="password :" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="74,63,0,0" Height="30" Width="55" FontFamily="B Nazanin" FontSize="15" Grid.Column="1"/>
<Label x:Name="lblwrong" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,150,0,0" ClipToBounds="True" Grid.Column="1" Height="26" Width="275"/>
<Button x:Name="btnLogin" Content="Login" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Grid.Column="1" Margin="211,103,0,0" Height="37" Background="White" Click="btnLogin_Click" BorderBrush="Red" FontFamily="B Nazanin" FontSize="15"/>
<Image HorizontalAlignment="Left" Height="117" Margin="4,23,0,0" VerticalAlignment="Top" Width="178" Source="img/Ticket_5523675581838074942.png" Grid.ColumnSpan="2" RenderTransformOrigin="0.5,0.128"/>
<Button x:Name="btnExit" Content="Exit" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Grid.Column="1" Margin="146,103,0,0" Height="37" Background="#FFFDFDFD" BorderBrush="Red" Click="Button_btnExit" FontFamily="B Nazanin" FontSize="15"/>
<TextBox x:Name="txtUsername" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="125" Grid.Column="1" Margin="146,34,0,0" BorderBrush="#FFF7311E"/>
<PasswordBox x:Name="txtPassword" Grid.Column="1" HorizontalAlignment="Left" Margin="146,70,0,0" VerticalAlignment="Top" Width="125" Height="23" BorderBrush="#FFFD3306"/>
</Grid>
</Window>
Any Reference/hint or Tutorial/link would be lovely. thank you in advance
You have to set Margin / Padding instead of explicit Width / Height if you want your controls to grow / shrink.
Few links to help you :
Layout with Absolute and Dynamic Positioning
How to make all controls resize accordingly proportionally when window is maximized?
Controls do not resize if you set their Width and Height properties explicitly. Try the following, I removed the Width and Height properties and changed the HorizontalAlignment and VerticalAlignment values to Stretch.
<Window x:Class="WPF_Working_Experimenet.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="216.586" Width="459.256">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="156*"/>
<ColumnDefinition Width="295*"/>
</Grid.ColumnDefinitions>
<Label Content="username :"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
FontFamily="B Nazanin"
FontSize="15"
Grid.Column="1"/>
<Label Content="password :"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
FontFamily="B Nazanin"
FontSize="15"
rid.Column="1"/>
<Label x:Name="lblwrong"
Content=""
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="True"
Grid.Column="1"/>
<Button x:Name="btnLogin"
Content="Login"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="1"
Background="White"
Click="btnLogin_Click"
BorderBrush="Red"
FontFamily="B Nazanin"
FontSize="15"/>
<Image HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Source="img/Ticket_5523675581838074942.png"
Grid.ColumnSpan="2"
RenderTransformOrigin="0.5,0.128"/>
<Button x:Name="btnExit"
Content="Exit"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="1"
Background="#FFFDFDFD"
BorderBrush="Red"
Click="Button_btnExit"
FontFamily="B Nazanin"
FontSize="15"/>
<TextBox x:Name="txtUsername"
HorizontalAlignment="Stretch"
TextWrapping="Wrap"
VerticalAlignment="Stretch"
Grid.Column="1"
BorderBrush="#FFF7311E"/>
<PasswordBox x:Name="txtPassword"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="#FFFD3306"/>
</Grid>
</Window>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="View/Images/LoginImg.jpg" Stretch="Fill" Grid.Column="0" Grid.ColumnSpan="3">
<Image.Effect>
<BlurEffect Radius="8"/>
</Image.Effect>
</Image>
<TextBox Grid.Column="0" Grid.ColumnSpan="3" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Foreground="White" HorizontalAlignment="Center"
Height="78" Margin="122,10,45.6,0" TextWrapping="Wrap" Text="Library Management System " VerticalAlignment="Top" Width="594" FontSize="40" FontWeight="Bold" FontStyle="Normal">
<TextBox.VerticalContentAlignment>Center</TextBox.VerticalContentAlignment>
<TextBox.IsReadOnly>True</TextBox.IsReadOnly>
</TextBox>
<Canvas Grid.Column="1" HorizontalAlignment="Stretch" Width="auto" Height="300" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Background="White">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="0.627"/>
<TranslateTransform/>
</TransformGroup>
</Canvas.RenderTransform>
<Label Content="Login" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Background="BurlyWood" FontSize="15" Height="52" Width="254">
<Label.FontWeight>Bold</Label.FontWeight>
</Label>
<TextBox Height="24" Canvas.Left="20" TextWrapping="Wrap" Text="User Name" TextAlignment="Center" Canvas.Top="84" Width="120" Foreground="Gray"/>
<PasswordBox Canvas.Left="20" Canvas.Top="136" Height="34" Width="120"/>
</Canvas>
</Grid>
Setting the horizontal and vertical alignment to stretch instead of setting width and height of the widget will do the trick. But still you can set a margin if you want. Tried this out and it ensured that when the window size is changed the widget will adjust respectively.

KeyboardNavigation.TabNavigation="Once" on Toolbar does not lose focus unless all elemets are contained in another container

In the XAML below, the first toolbar (Toolbar1 below) does not lose focus and traverses all elements even with KeyboardNavigation.TabNavigation="Once" set. The only way I have make it work is by putting all elements of the toolbar into another container such as stack panel or grid (Toolbar2 below). However, then overflow functionality does not work appropriately. When width is reduced, whole inside container overflows instead of individual items.
My requirement is to tab out from the toolbar after first element (for remaining items user will use the arrow keys) without losing the overflow functionality of overflowing individual items as needed.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="100" />
<RowDefinition Height="50" />
<RowDefinition Height="100" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="First" Width="600"></TextBox>
<TextBox Grid.Row="1" Text="Second" Width="600"></TextBox>
<DockPanel LastChildFill="True" Grid.Row="2" Background="Red" >
<ToolBar x:Name="Toolbar1" DockPanel.Dock="Top"
VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="40" BandIndex="1" Band="1"
KeyboardNavigation.TabNavigation="Once" >
<Button Background="Red" Content="1" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
<Button Background="Red" Content="2" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
<Button Background="Red" Content="3" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
<Button Background="Red" Content="4" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
<Button Background="Red" Content="5" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
</ToolBar>
<TextBox DockPanel.Dock="Bottom" Text="I'm first Rich Text Box, My toolbar is not in a inner container." Height="50" Width="600"></TextBox>
</DockPanel>
<TextBox Grid.Row="3" Text="Third" Width="600"></TextBox>
<DockPanel LastChildFill="True" Grid.Row="4" Background="Green">
<ToolBar x:Name="Toolbar2" DockPanel.Dock="Top"
VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="40" BandIndex="1" Band="1"
KeyboardNavigation.TabNavigation="Once" >
<StackPanel Orientation="Horizontal" KeyboardNavigation.TabNavigation="Once" >
<Button Background="Green" Content="1" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded" />
<Button Background="Green" Content="2" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded"/>
<Button Background="Green" Content="3" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded"/>
<Button Background="Green" Content="4" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded"/>
<Button Background="Green" Content="5" Height="28" Width="28" ToolBar.OverflowMode="AsNeeded"/>
</StackPanel>
</ToolBar>
<TextBox DockPanel.Dock="Bottom" Text="I'm second Rich Text Box, My toolbar is in a inner container." Height="50" Width="600"></TextBox>
</DockPanel>
<TextBox Grid.Row="5" Text="Fourth" Width="600"></TextBox>
</Grid>
As I get correct you should turn off FocusManager.IsFocusScope attached property for your ToolBar1, don't I?

WPF Grid Items and Right Aligned Text

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>

Resources