How to overlay two gauge controls? - wpf

I've set up binding of a double value to an AngularBlockBar control. There are two gauges in the layout, but the AngularBlockBar which is over layed on top of the AngularGauge doesn't show its binding value updating on screen, although valid binding values are being updated to it.
To debug this, I've checked first that the binding value that is bound to the AngularBlockBar is valid and this shows as true by setting a break point.
The binding value shows as valid.
I'm thinking its because of the way the two gauges are over layed over each other, which causes the AngularBlockBar's binding to not show.
Does anyone know what the issue could be here, that prevents the AngularblockBar's binding from being shown on screen?
The layout below is the main user control of the application where the two gauges are over layed. The first gauge updates correctly with a white fill value as shown in the screen shot below. But the AngularBlockBar which has a blue fill value isn't updated
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:gauges="http://gu.se/Gauges"
xmlns:local="clr-namespace:MyoTestv4"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="MyoTestv4.AdductionAbductionFlexionView"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Viewbox>
<Grid HorizontalAlignment="Left" Height="280" Margin="10,10,0,0" VerticalAlignment="Top" Width="280">
<TextBox HorizontalAlignment="Left" x:Name="statusTbx" Background="#141c28" Foreground="White" BorderBrush="#141c28" Height="30" Margin="0,3,0,0" TextWrapping="Wrap" Text="{Binding CurrentStatus}" VerticalAlignment="Top" Width="75"/>
<TextBox HorizontalAlignment="Left" x:Name="poseStatusTbx" Background="#141c28" Foreground="White" BorderBrush="#141c28" Height="39" Margin="80,4,0,0" TextWrapping="Wrap" Text="{Binding PoseStatus}" VerticalAlignment="Top" Width="75"/>
<TextBox HorizontalAlignment="Left" x:Name="degreeOfAbductionTbx" Background="#141c28" Foreground="White" Height="22" Margin="0,246,0,0" TextWrapping="Wrap" Text="{Binding DegreeStatus}" VerticalAlignment="Top" Width="47"/>
<Label Content="Arc start:" Foreground="#00bdde" HorizontalAlignment="Left" Margin="0,186,0,0" VerticalAlignment="Top" Width="57"/>
<Image HorizontalAlignment="Left" Source="pack://application:,,,/Images/abduction_side_trans.png" x:Name="exerciseImage" Height="100" Margin="0,33,0,0" VerticalAlignment="Top" Width="100"/>
<TextBox HorizontalAlignment="Left" x:Name="painfulArcEndTbx" Background="#141c28" Foreground="White" Height="22" Margin="62,217,0,0" TextWrapping="Wrap" Text="{Binding EndDegreeStatus}" VerticalAlignment="Top" Width="48"/>
<Label Content="Arc end:" Foreground="#00bdde" HorizontalAlignment="Left" Margin="0,217,0,0" VerticalAlignment="Top" Width="57"/>
<TextBox HorizontalAlignment="Left" x:Name="painfulArcStartTbx" Background="#141c28" Foreground="White" Height="23" Margin="62,189,0,0" TextWrapping="Wrap" Text="{Binding StartDegreeStatus}" VerticalAlignment="Top" Width="48"/>
<Grid>
<gauges:AngularGauge
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsDirectionReversed="False"
MajorTickFrequency="8"
FontSize="10"
MajorTicks="10"
MaxAngle="0"
Maximum="180"
MinAngle="-180"
Minimum="0"
Style="{StaticResource FatAngular}"
MinorTickFrequency="4"
Value="{Binding DegreeStatus}" Margin="149,2,-89,2" RenderTransformOrigin="0.5,0.5" Height="Auto" Width="Auto"
>
<gauges:AngularGauge.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-89.642"/>
<TranslateTransform/>
</TransformGroup>
</gauges:AngularGauge.RenderTransform>
</gauges:AngularGauge>
<gauges:AngularBlockBar
MaxAngle="180"
Maximum="1"
MinAngle="0"
Minimum="0"
Opacity="0.2"
ReservedSpace="50"
Margin="149,2,-96,0"
TickLength="55"
Fill="DodgerBlue"
Value="{Binding PainfulArcStatus}"
RenderTransformOrigin="0.5,0.5" >
<gauges:AngularBlockBar.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="90.711"/>
<TranslateTransform/>
</TransformGroup>
</gauges:AngularBlockBar.RenderTransform>
</gauges:AngularBlockBar>
</Grid>
<TextBlock HorizontalAlignment="Left" x:Name="repCntTblk" Margin="80,43,0,0" TextWrapping="Wrap" Text="" FontSize="38" Foreground="#00bdde" VerticalAlignment="Top" Width="34" Height="41"/>
<Button Content="Submit" x:Name="submitBtn" Command="{Binding Path=DataSubmitCommand}" IsDefault="True" IsCancel="True" HorizontalAlignment="Left" Background="#00bdde" Foreground="White" Margin="0,148,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.76,5.093"/>
</Grid>
</Viewbox>
</UserControl>
The first gauge binding being shown, but the over layed value for the block bar isn't shown.

Don't you need to define Grid.Column and/or Grid.Row on your guage and blockbar other wise they will just lay ontop of eachother?
example with Grid.ColumnDefinitions, you probably want RowDefinitions
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100px"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ComboBox ItemsSource="{Binding NavigationItems}" SelectedItem="{Binding SelectedNavigationItem, Mode=TwoWay}" Grid.Row="0" Grid.Column="0">
</ComboBox>
<ContentControl Content="{Binding SelectedNavigationItem}" Grid.Row="0" Grid.Column="1"/>
</Grid>

Related

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.

FaceTrackingBaciscWPF example - how to make facetrackingviewer scale?

I am working with FaceTrackingBaciscWPF example and I wanted to change the layout of MainWindow.xaml, so that it contains 2 columns - ColorViewer with overlayed skeleton in the first one and some text fields in the second one.
When I introduce rows and columns, the colorimage scales as expected, but I don't know how to make rendered face and skeleton "fit" the color image. How to make the faceTrackingViewer scale too?
Below my MainWindow.xaml.
<Window
x:Class="FaceTrackingBasics.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FaceTrackingBasics"
Title="Face Tracking Basics"
Closed="WindowClosed"
Height="849.925" Width="1017.761"
>
<Window.Resources>
<SolidColorBrush x:Key="MediumGreyBrush" Color="#ff6e6e6e"/>
<SolidColorBrush x:Key="KinectPurpleBrush" Color="#ff52318f"/>
<SolidColorBrush x:Key="KinectBlueBrush" Color="#ff00BCF2"/>
<Style TargetType="{x:Type Image}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>
</Window.Resources>
<Grid Name="layoutGrid" Margin="10,0,-83,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0" Margin="0 0 0 20">
<Image DockPanel.Dock="Left" Source="Images\Logo.png" Stretch="Fill" Height="32" Width="81" Margin="0 10 0 5"/>
<TextBlock DockPanel.Dock="Right" Margin="0 0 -1 0" VerticalAlignment="Bottom" Foreground="{StaticResource MediumGreyBrush}" FontFamily="Segoe UI" FontSize="18">Face Tracking Basics</TextBlock>
<Image Grid.Column="1" Source="Images\Status.png" Stretch="None" HorizontalAlignment="Center" Margin="0 0 0 5"/>
</DockPanel>
<Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Center">
<Grid Name="MainGrid" Width="707" Height="417">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Image Name="ColorImage" Margin="0,0,0,0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="400" Height="480"/>
<local:FaceTrackingViewer Margin="0,0,0,0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="400" Height="480" x:Name="faceTrackingViewer"/>
<Label Content="curHeadZ" Grid.Column="1" HorizontalAlignment="Left" Margin="6,94,0,0" VerticalAlignment="Top"/>
<Label Content="curNoseZ" Grid.Column="1" HorizontalAlignment="Left" Margin="9,63,-4,0" VerticalAlignment="Top"/>
<Label Content="shiftHead" Grid.Column="1" HorizontalAlignment="Left" Margin="5,37,-1,0" VerticalAlignment="Top"/>
<Label Content="shiftNose" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,-6,0" VerticalAlignment="Top"/>
<TextBox Name="curHeadZ" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="82,96,-130,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox Name="curNoseZ" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="79,69,-128,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox Name="shiftHeadZ" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="80,41,-130,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox Name="shiftNoseZ" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="79,13,-130,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Label Content="pitch" Grid.Column="1" HorizontalAlignment="Left" Margin="6,125,0,0" VerticalAlignment="Top"/>
<Label Content="roll" Grid.Column="1" HorizontalAlignment="Left" Margin="6,151,0,0" VerticalAlignment="Top"/>
<Label Content="yaw" Grid.Column="1" HorizontalAlignment="Left" Margin="6,177,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="pitchValText" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="82,128,-128,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="rollValText" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="82,156,-126,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="yawValText" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="82,180,-124,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Button Content="TakePicture" Grid.Column="1" HorizontalAlignment="Left" Margin="11,226,0,0" VerticalAlignment="Top" Width="75" Click="TakePictureButtonColor_Click"/>
</Grid>
</Viewbox>
</Grid>
</Window>
Probably it's something obvious that I am missing here, but I am just beginning so please help.
I think you need to remove the Width & Height specifiers from the XAML as follows:
<local:FaceTrackingViewer Margin="0,0,0,0"
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
x:Name="faceTrackingViewer"/>

Grid Not Filling Available Space with XAML

I am very, very new to XAML. I'm using Visual Studio Express 2013 and I'm in WPF having problems getting a grid's labels, textboxes, and checkboxes to fill the remaining white space when a form is maximized or resized. The controls all get slightly larger, but then stop at about a 25-33% increase in size. I have borders under each text box to make the textboxes stand out on the form.
I'm thinking that the answer may lie in putting grid.columdefinitions and rowdefinitions around each control and setting the height and width to '*' rather than just slapping them all in a large one-cell grid. I apologize for the lengthy attributes, I was trying several solutions and using GUI.
Grid x:Name="Form"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="500" Height="620" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid.Resources>
<XmlDataProvider x:Key="xmlData" XPath="/data" IsAsynchronous="False">
<x:XData>
<data xmlns="">
</data>
</x:XData>
</XmlDataProvider>
</Grid.Resources>
<Label Content="TEST PAGE 1" Margin="103,4,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1"/>
<TextBox x:Name="line1box" Height="18" Margin="313,0,0,0" TextWrapping="Wrap" Width="37" TextAlignment="Center" BorderThickness="0" MaxLines="1" MaxLength="4" FontSize="10"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Margin="313,17,0,0" Width="37" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1"/>
<Label Content="Line 1" Margin="350,3,0,0" RenderTransformOrigin="-0.233,0.493" FontSize="9" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1"/>
<Label Content="Line 2" Margin="350,21,0,0" RenderTransformOrigin="-0.233,0.493" FontSize="9" HorizontalAlignment="Left" Padding="5" VerticalAlignment="Top" Grid.RowSpan="2" Grid.Column="1"/>
<TextBox x:Name="line2box" Margin="313,19,0,0" TextWrapping="Wrap" Width="37" TextAlignment="Center" BorderThickness="0" MaxLines="1" MaxLength="4" FontSize="10" TabIndex="2" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.RowSpan="2" Grid.Column="1"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Margin="313,5,0,0" Width="37" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<CheckBox x:Name="check1" Content="check1" Margin="312,18,0,0" FontSize="9" TabIndex="3" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<CheckBox x:Name="check2" Content="check2" Margin="361,18,0,0" FontSize="9" TabIndex="4" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<Label Content="Line 3" Margin="0,31,0,0" FontSize="9" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1"/>
<TextBox x:Name="insured" Margin="56,33,0,0" TextWrapping="Wrap" Width="265" BorderThickness="0" Height="25" AcceptsReturn="True" MaxLines="2" FontSize="10" TabIndex="5" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="2"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Height="1" Margin="56,45,0,0" Width="265" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="2"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Height="1" Margin="56,57,0,0" Width="265" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="2"/>
<Label Content="Line 4" Margin="269,34,0,0" RenderTransformOrigin="-0.233,0.493" FontSize="9" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<TextBox x:Name="line4box" Margin="309,37,0,0" Width="107" BorderThickness="0" FontSize="9" MaxLines="2" TabIndex="6" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Margin="309,49,0,0" Width="107" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<Label Content="line5" Margin="261,48,0,0" RenderTransformOrigin="-0.233,0.493" FontSize="9" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<TextBox x:Name="line5box" Margin="309,50,0,0" Width="107" BorderThickness="0" FontSize="9" MaxLines="2" TabIndex="7" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
<Border BorderBrush="Black" BorderThickness="0,0,0,1" Margin="309,63,0,0" Width="107" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"/>
This is the main problem when using the Visual Studio designer to create XAML-based UIs rather than creating XAML by hand.
Basically, all your UI elements have Hardcoded, fixed positions defined by their margins, for example:
<Label .. Margin="350,21,0,0" ... />
which constrain their maximum size, rather than having relative positions determined by their parent container and stretching to the available space.
Please have a look at WPF Layout Tutorial for introductory material on how to create XAML-based layouts in a proper fashion.

WPF application changing size

So, it is my first time working with a wpf application in VS 2012 for windows desktop.
I put some background image in to a window. I put three text boxes and a button on to that window. Now I have a problem, when I start the application and I change the size of a window with mouse or go fullscreen, the window changes its size, but textboxes and button stay at the same position as before, and they do not really fit into that design. I hope I was clear enough. Thank you for your help.
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="768" Width="1366
">
<Grid RenderTransformOrigin="0.495,0.498" Margin="0,10,0,0">
<Grid.Background>
<ImageBrush ImageSource="slike/education_board.jpg"/>
</Grid.Background>
<Grid HorizontalAlignment="Left" Height="209" Margin="209,211,0,0" VerticalAlignment="Top" Width="396">
<TextBox x:Name="tockeMaturaTextBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="120" TextChanged="TextBox_TextChanged_1" IsManipulationEnabled="True" Margin="10,0,0,176"/>
<TextBox x:Name="tretjiLetnikTextBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.899,3.574" Margin="10,63,0,0"/>
<TextBox x:Name="cetrtiLetnikTextBox" HorizontalAlignment="Left" Height="23" Margin="10,115,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="361,224,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<TextBlock x:Name="skupneTockeTextBlock" HorizontalAlignment="Left" Margin="323,133,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" RenderTransformOrigin="-0.375,0.338" Height="73" Width="113"/>
</Grid>
</Grid>
</Window>
Give the XAML below a try:
<Grid Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="211"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<ImageBrush ImageSource="slike/education_board.jpg"/>
</Grid.Background>
<StackPanel Grid.Row="1" Grid.Column="1" >
<TextBox x:Name="tockeMaturaTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="120" TextChanged="TextBox_TextChanged_1" IsManipulationEnabled="True" />
<TextBox x:Name="tretjiLetnikTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" />
<TextBox x:Name="cetrtiLetnikTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Button x:Name="button" Margin="5" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<TextBlock x:Name="skupneTockeTextBlock" Margin="5" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="73" Width="113"/>
</StackPanel>
</Grid>
WPF uses a container-based (relative) layout system. You were placing your textboxes in absolute positions by defining their margins precisely with respect to the parent grid. In the example above, they are placed in a StackPanel which is inside the grid.
With all the extra margins and absolute widths and heights, it's hard to tell what final result you are going for, but the XMAL above should get you close. You can change the relative sizes of the grid rows and columns to get what you need; or completely redefine the structure of the Grid.
I think a good tutorial on WPF is in order to get a handle on the basic conocepts:
Silverlight/WPF Introduction. This is geared a little bit towards Silverlight, but the layout principles are identical to WPF. Actual training starts at 8:17 in the video.
EDIT
For magical expanding and shrinking content, use the code below:
<Grid Margin="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<ImageBrush ImageSource="slike/education_board.jpg"/>
</Grid.Background>
<Viewbox Grid.Row="1" Grid.Column="1" >
<StackPanel>
<TextBox x:Name="tockeMaturaTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="120" TextChanged="TextBox_TextChanged_1" IsManipulationEnabled="True" />
<TextBox x:Name="tretjiLetnikTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" />
<TextBox x:Name="cetrtiLetnikTextBox" Margin="0,5" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Button x:Name="button" Margin="5" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<TextBlock x:Name="skupneTockeTextBlock" Margin="5" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="73" Width="113"/>
</StackPanel>
</Viewbox>
</Grid>

How can I stop the page from snapping back to its original position

I have implemented a ScrollViewer around the content panel grid in my Windows Phone 7 page. However, whenever I try and scroll down to the bottom of the page, it snaps right back to it's original position the moment I take my finger off the screen. In other words on scrolling it does not retain it's last position rendering the scroll pointless.
This is my page code:
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71" x:Class="StepsForWater.Views.Submit"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="696"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Submit, Source={StaticResource Locator}}">
<!-- Sample code showing usage of ApplicationBar -->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="appbar_About" IconUri="/Images/appbar_button1.png" Text="About" Click="appbar_About_Click"/>
<shell:ApplicationBarIconButton x:Name="appbar_WalkRun" IconUri="/Images/appbar_button2.png" Text="Walk/Run" Click="appbar_WalkRun_Click"/>
<!--<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"></shell:ApplicationBarMenuItem>
<shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"></shell:ApplicationBarMenuItem>
</shell:ApplicationBar.MenuItems>-->
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="/StepsForWater;component/Images/submit-bg.png" />
</Grid.Background>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="12,17,0,28">
<!--<TextBlock x:Name="ApplicationTitle"
Text="MY APPLICATION"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock x:Name="PageTitle"
Text="page name"
Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle1Style}" />-->
</StackPanel>
<ScrollViewer>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,-241" Background="{x:Null}">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,57,0,0" x:Name="tBlk_Username" Text="{Binding UserName}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,79,0,0" x:Name="tb_UserNameVal" Text="{Binding UserNameValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,169,0,0" x:Name="tBlk_Email" Text="{Binding Email}" VerticalAlignment="Top" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,278,0,0" x:Name="tBlk_Message" Text="{Binding Message}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,191,0,0" x:Name="tb_EmailVal" Text="{Binding EmailValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBox Height="153" HorizontalAlignment="Left" Margin="27,300,0,0" x:Name="tb_MessageVal" Text="{Binding MessageValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<CheckBox Content="{Binding Location}" Height="72" HorizontalAlignment="Left" Margin="27,459,0,0" x:Name="chk_Location" VerticalAlignment="Top" />
<Button Content="{Binding Submit}" Height="72" HorizontalAlignment="Left" Margin="27,761,0,0" x:Name="btn_Submit" VerticalAlignment="Top" Width="160" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="SubmitClick" Command="{Binding SubmitCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBlock Height="30" HorizontalAlignment="Left" Margin="50,540,0,0" Name="tBlk_PicInfo" Text="{Binding PictureInfo}" VerticalAlignment="Top" Grid.Row="1" />
<Image Height="150" HorizontalAlignment="Left" Margin="50,583,0,0" Name="img_FlickrPic" Stretch="Fill" VerticalAlignment="Top" Width="200" Grid.Row="1" Source="{Binding ImageSource}"/>
<Button Content="Capture" Height="72" HorizontalAlignment="Left" Margin="267,0,0,138" Name="btn_Capture" VerticalAlignment="Bottom" Width="160" d:LayoutOverrides="GridBox" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="CaptureClick" Command="{Binding CaptureCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</ScrollViewer>
</Grid>
Update: Fixed my problem, all I needed to do was to ensure that my scrollviewer's height was less than that of it's contained grid!
As mentioned by others you should probably rethink the way your making your layout. There are cleaner options. But to answer your question, there were two problems. The first is that you need to specify a Height on the ScrollViewer.
<ScrollViewer Height="760">
....
</ScrollViewer>
The second problem is the negative margin of 241 you have applied to the grid. Simply take that off. It's preventing anything within that range of being scrolled to.
<Grid x:Name="ContentPanel" Margin="12,0,12,0">
....
</Grid>
And that should do it.

Resources