WPF application changing size - wpf

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>

Related

WPF Telerik Controls not Visible in Design Mode

I am using Telerik framework on WPF/C# project and controls are not visible in design. When I run the app, the controls (eg., RadButton) is displayed fine. Why is this happening? While default controls are working just
<Window x:Class="TelerikWpfApp4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="MainWindow" Height="350" Width="525">
<Grid>
<telerik:RadRadioButton x:Name="radRadioButton" Content="Button" HorizontalAlignment="Left" Height="Auto" IsChecked="False" VerticalAlignment="Top" Width="Auto" Margin="24,42,0,0"/>
<telerik:RadListBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="250">
<telerik:RadListBoxItem Content="Item 1"/>
<telerik:RadListBoxItem Content="Item 2"/>
<telerik:RadListBoxItem Content="Item 3"/>
</telerik:RadListBox>
<telerik:RadToggleButton x:Name="radToggleButton" Content="Button" HorizontalAlignment="Left" Height="Auto" IsThreeState="False" IsChecked="False" VerticalAlignment="Top" Width="Auto"/>
<telerik:DataFormDateField HorizontalAlignment="Left" VerticalAlignment="Top" Margin="322,85,0,0"/>
<telerik:RadSplitButton Content="Button" HorizontalAlignment="Left" Height="Auto" IsOpen="False" IsChecked="False" VerticalAlignment="Top" Width="Auto"/>
<telerik:RadSplitButton Content="Button" HorizontalAlignment="Left" Height="Auto" IsOpen="False" IsChecked="False" VerticalAlignment="Top" Width="Auto"/>
<telerik:RadRadioButton x:Name="radRadioButton1" Content="Button" HorizontalAlignment="Left" Height="Auto" IsChecked="False" VerticalAlignment="Top" Width="Auto"/>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="175,142,0,0"/>
<telerik:RadButton x:Name="radButton" Content="segfsdhshdh" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="Auto" Margin="21,32,0,0"/>
</Grid>
I have had this issue before, and it had to do with the referenced assembly I was using. Telerik has two assembly reference types xaml and noxaml, once I deleted my references and replaced them with the correct ones, I had no issues. Here are a couple of links to the Telerik documentation about the issue:
https://docs.telerik.com/devtools/wpf/common-information/troubleshooting/invisible-controls
https://docs.telerik.com/devtools/wpf/styling-and-appearance/xaml-vs-noxaml

Keeping correct XAML layout when browser is resized

I have a XAML window that the layout is done using a main grid. The problem is when the browser is resized the controls in the second and third columns move to the right and the window's layout is no longer correct. I have pasted the XAML below. I think the layout of a WPF window should be grid based with all controls residing in the window's master grid. Is this the proper layout design for WPF or is there a different recommended layout pattern?
<Window x:Class="MasterPage.Intake1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage.View"
Title="Intake 1" Height="900" Width="1000" Background="#FFD9DDE8" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="190*"/>
<RowDefinition Height="275*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="300*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0">
<Image Source="Images\header.jpg" Height="47" Margin="0,0,0,0" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Grid.Column="0" Height="80" Width="350" Grid.ColumnSpan="1" Grid.Row="1" Margin="0,-23,0,0">
<Image Source="Images\DSPASS_logo.png" Stretch="Fill" DockPanel.Dock="Top" Height="70" />
</StackPanel>
<StackPanel Grid.Column="4" Grid.Row="1" Grid.ColumnSpan="1" Margin="0,0,0,0">
<TextBlock FontSize="15" Margin="0,0,0,0" Height="25" Width="300" TextWrapping="WrapWithOverflow">
<Label FontSize="10" Name="Namelabel" Width="250" FontWeight="Bold" Foreground="#1664A1" Content="Welcome to DS PASS:"/>
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="10,10,0,0" Height="290" Width="975" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.RowSpan="1">
<Label Height="36" FontSize="16" Content="Post Identification" Background="#FF014E7E" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_wordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="ApplicantType_TextBlock" Text="Applicant Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_integerWordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="textBlockIntegerWordLength" Text="Person Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxIntegerWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_Post" Orientation="Horizontal" Margin="235,0,200,20">
<TextBlock Height="20" x:Name="Post_TextBlock" Text="Post" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="Post_TextBox" Width="400" Margin="10,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Height="130" Margin="15,-120,0,0" VerticalAlignment="Top" Grid.ColumnSpan="3" >
<Label Height="36" FontSize="16" Content="Applicant Employment" Background="#FF004A78" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_max1" Orientation="Vertical" Margin="1,0,355,0">
<TextBlock Height="20" x:Name="maxTextBlock1" Text="Employee ID" Width="100" Foreground="Black" Margin="0,15,459,5" TextAlignment="Right"/>
<TextBox Height="25" x:Name="maxTextBox1" Width="400" Margin="0,-5,90,25"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Orientation="Vertical" HorizontalAlignment="Left" Height="330" Margin="0,10,0,0" VerticalAlignment="Top" Width="965" Grid.RowSpan="2">
<Label Height="36" FontSize="16" Content="English Version of Name" Background="#FF005183" Grid.Row="4" FontWeight="Bold" Margin="10,10,0,0" Foreground="White" Padding="4,5,5,5"/>
<StackPanel x:Name="_LastName" Orientation="Vertical">
<TextBlock Height="20" x:Name="LastName_TextBlock" Text="Last Name/Surname" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="LastName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_FirstName" Orientation="Vertical">
<TextBlock Height="20" x:Name="FirstName_TextBlock" Text="First Name" Margin="55,0,459,0" TextAlignment="Left"/>
<TextBox Height="25" x:Name="FirstName_TextBox" Width="500" Margin="55,0,459,0"/>
</StackPanel>
<StackPanel x:Name="_MiddleName" Orientation="Vertical">
<TextBlock Height="20" x:Name="MiddleName_TextBlock" Text="Middle Name" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="MiddleName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_ExtendedName" Orientation="Vertical">
<TextBlock Height="20" x:Name="ExtendedName_TextBlock" Text="Extended name (Tribal, Jr., III, etc.)" Margin="55,5,372,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Extended_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.RowSpan="4" Grid.Column="4" HorizontalAlignment="Left" Height="230" Margin="-250,400,0,0" Width="480" Grid.ColumnSpan="1">
<StackPanel x:Name="_Aliases" Orientation="Vertical" Margin="-15,0,0,0" Height="144">
<TextBlock Height="20" x:Name="Aliases_TextBlock" Text="Aliases" Margin="40,-5,0,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Aliases_TextBox" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox1" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox2" Width="500" Margin="43,5"/>
</StackPanel>
</StackPanel>
<!--<Label HorizontalAlignment="Left" Margin="4,132,0,0" Grid.Row="3" VerticalAlignment="Top" Background="#FF72C772" Grid.ColumnSpan="3" Width="1242" Height="36"/>
<Button Content="Continue" Grid.Column="2" HorizontalAlignment="Left" Margin="16,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125" Click="Page1_Continue_Click"/>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="336,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125"/>-->
<Label HorizontalAlignment="Left" Margin="4,400,0,0" Grid.Row="4" VerticalAlignment="Top" Background="#FF52BB52" Grid.ColumnSpan="3" Width="983" Height="36">
</Label>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="150,408,0,0" Grid.Row="5" VerticalAlignment="Top" Width="125" />
<Button x:Name="ContinueButton_Page2" Content="Continue" Grid.Column="1" Width="125" Grid.Row="5" VerticalAlignment="Top" Margin="200,408,0,0" Grid.ColumnSpan="2" Click="btnContinue_Click"/>
</Grid>
</Window>
When you want control of the alignment during resizing, think Grid. In more complex situations, think Grids inside a Grid. A picture says it better
You have your MainGrid with only rows, no columns. The blue headers get rows of their own and
the orange containers are Grids themselves (with possibly a margin left and right).
Now you shouldn't try to divide the available space with all "...*" width values.
In this example you could use it for dead space only, e.g. the yellow columns with Width="*".
The blue columns would be Width="Auto" (or pixels).
Topping it off with a MinWidth for the Window corresponding with the width you need for the bottom Grid. Also consider wrapping your MainGrid in a ScrollViewer.
What I needed was to not allow resizing of the web browser. To do this I removed the minimize/maximize buttons To do that I used the following attribute:
ResizeMode="NoResize"

How to overlay two gauge controls?

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>

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"/>

C# WPF Dynaically adding tabs byt loading xaml file clears radio buttons, why?

So I have a window that contains a TabControl as the main UI element. I add two tabs by default in the xaml editor. When the program runs I want to add new tabs that have identical setups (but are different than the first two tabs). I can do this by calling:
URLTabContentControl documentRoot = (URLTabContentControl)Application.LoadComponent(new Uri(#"URLTabContentControl.xaml", UriKind.Relative));
Which loads up a control I have defined in a xaml file. Basically this is what I want to show up inside of the new tab I will add. At this point I call:
TabItem ti = new TabItem();
ti.Header = "*New Capture URL " + (mainTabControl.Items.Count-1);
ti.Content = documentRoot;
int i = mainTabControl.Items.Add(ti);
mainTabControl.SelectedIndex = i;
Which creates the new TabItem adds a header and the control that was create via the xaml file. The issue is the xaml file has several different radio button groups and everytime I add a new tab the radio buttons on the existing tabs all become unselected. I don't think this is a bug in my code so I'm wondering if anyone can point me in the right direction. None of the other types of controls have their state screwed up like this.
This is the xaml that becomes the content of the TabItems:
<UserControl x:Class="CustomCamApplication.URLTabContentControl"
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"
mc:Ignorable="d"
d:DesignHeight="340" d:DesignWidth="634">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45*" />
<RowDefinition Height="42*" />
<RowDefinition Height="41*" />
<RowDefinition Height="31*" />
<RowDefinition Height="34*" />
<RowDefinition Height="29*" />
<RowDefinition Height="118*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="101*" />
<ColumnDefinition Width="105*" />
<ColumnDefinition Width="65*" />
<ColumnDefinition Width="45*" />
<ColumnDefinition Width="30*" />
<ColumnDefinition Width="88*" />
<ColumnDefinition Width="200*" />
</Grid.ColumnDefinitions>
<Label Content="URL Suffix:" Height="28" HorizontalAlignment="Right" Margin="0,12,0,0" Name="urlSuffixLabel" VerticalAlignment="Top" ToolTip="Enter the part of the path that will be after the domain. http://my.domain.com:port/(enter this part)" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="6,14,0,0" Name="textBox1" VerticalAlignment="Top" Width="401" Grid.Column="1" Grid.ColumnSpan="6" />
<Label Content="Video Source:" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="videoSourceLabel" VerticalAlignment="Top" Grid.Row="1" ToolTip="Select the video source you want to use for this URL." />
<ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="6,10,0,0" Name="videoSourceComboBox" VerticalAlignment="Top" Width="401" Grid.Row="1" Grid.ColumnSpan="6" SelectionChanged="videoSourceComboBox_SelectionChanged" />
<Label Content="Captured Image" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="capturedImageLabel" VerticalAlignment="Top" Width="101" />
<Label Content="Filename Prefix:" Grid.Column="1" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="filenamePrefixLabel" VerticalAlignment="Top" Width="95" ToolTip="Enter the front part of the file names used for capture file by this video source. Example prefix1002.png" />
<TextBox Grid.Column="2" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="6,12,0,0" Name="filenamePrefixTextBox" VerticalAlignment="Top" Width="120" Text="capture" Grid.ColumnSpan="3" />
<Label Content="Capture Type:" Grid.Row="5" Height="28" HorizontalAlignment="Right" Name="captureTypeLabel" VerticalAlignment="Top" Width="83" ToolTip="Store only a single image or store a series of images on the drive." />
<RadioButton Content="Single Image" Grid.Column="1" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSingleRadioButton" VerticalAlignment="Top" GroupName="captureType" IsChecked="True" />
<RadioButton Content="Series" Grid.Column="2" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSeriesRadioButton" VerticalAlignment="Top" GroupName="captureType" />
<Label Content="File Format:" Grid.Column="1" Grid.Row="3" Height="28" HorizontalAlignment="Right" Margin="0,3,0,0" Name="captureFormatLabel" VerticalAlignment="Top" Width="73" ToolTip="Select the format of the stored capture files." />
<RadioButton Content="PNG" Grid.Column="2" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="6,8,0,0" Name="fileFormatPNGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" IsChecked="True" />
<RadioButton Content="JPG" Grid.Column="3" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="0,8,0,0" Name="fileFormatJPGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" />
<RadioButton Content="BMP" Grid.Column="4" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="8,8,0,0" Name="fileFormatBMPRadioButton" VerticalAlignment="Top" GroupName="fileFormat" Grid.ColumnSpan="2" />
<CheckBox Content="Zero Pad Image Series Names" Grid.Column="5" Grid.Row="2" Height="16" HorizontalAlignment="Left" Margin="9,15,0,0" Name="filenameZeroPadCheckBox" VerticalAlignment="Top" ToolTip="Example prefix00001.png" Grid.ColumnSpan="2" />
<Label Content="Dimensions:" Grid.Column="1" Grid.Row="4" Height="28" HorizontalAlignment="Right" Margin="0,6,0,0" Name="captureDimensionsLabel" VerticalAlignment="Top" Width="73" />
<RadioButton Content="Source Default" Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="6,11,0,0" Name="captureDimensionsDefaultRadioButton" VerticalAlignment="Top" Width="94" GroupName="captureDimensions" IsChecked="True" ToolTip="The default capture size for the selected video source." Checked="captureDimensionsDefaultRadioButton_Checked" />
<Label Content="Capture Interval:" Grid.Row="6" Height="28" HorizontalAlignment="Right" Margin="0,5,0,0" Name="captureIntervalLabel" VerticalAlignment="Top" Width="101" ToolTip="Enter the number of seconds between frame captures." />
<TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" Height="23" HorizontalAlignment="Left" Margin="6,7,0,0" Name="catureIntervalTextBox" VerticalAlignment="Top" Width="120" Text="5" PreviewTextInput="captureIntervalTextBox_PreviewTextInput" DataObject.Pasting="captureIntervalTextBox_Pasting"/>
<RadioButton Content="Reported Mode" Grid.Column="4" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="8,11,0,0" Name="captureDimensionsSourceReportedRadioButton" VerticalAlignment="Top" GroupName="captureDimensions" ToolTip="Select a mode from one reported by the device." Checked="captureDimensionsSourceReportedRadioButton_Checked" />
<ComboBox Grid.Column="6" Grid.Row="4" Height="23" HorizontalAlignment="Left" Margin="0,6,0,0" Name="reportedModeComboBox" VerticalAlignment="Top" Width="174" IsEnabled="False" />
</Grid>
</UserControl>
Let's assume you have 3 groups of radio buttons on your URLTabContentControl control titled Group1, Group2, and Group3. When you dynamically create a TabItem based on URLTabContentControl that instance then has yet another group of radio buttons that have since expanded on your initial group definitions. Those 3 groups are not isolated to each instance per se.
One way to test this theory is to leave a single grouping of radio buttons on your URLTabContentControl control and remove the group name and let the framework handle the default behavior; it should work as expected now since there is no explicit group name tied to the radio buttons on URLTabContentControl

Resources