validating model in silverlight MVVM - c#

how to validate in model in silverlight?
The code sample what Im trying to achieve is shown below..
<Grid x:Name="AddnewGrid" Margin="2" DataContext="{Binding SaveUpdateEmp, Mode=TwoWay">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="EmployeeCode" Text="EmployeeCode" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeCodeSprtr" Text=":" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeCode" Text="{Binding EmployeeCode, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeeName" Text="Employee Name" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeNameSprtr" Text=":" FontSize="14" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeName" Text="{Binding EmployeeName, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeePW" Text="PassWord" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeePWSprtr" Text=":" FontSize="14" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeePW" Text="{Binding EmployeePW, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeeDesg" Text="Designation" FontSize="14" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeDesgSprtr" Text=":" FontSize="14" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeDesg" Grid.Row="3" Text="{Binding EmployeeDesg, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="DepartmentId" Text="DepartmentID" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="DepartmentIdSprtr" Text=":" FontSize="14" Grid.Row="4" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtDepartmentId" Grid.Row="4" Text="{Binding DepartmentId, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="DepartmentName" Text="Department" FontSize="14" Grid.Row="5" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="DepartmentNameSprtr" Text=":" FontSize="14" Grid.Row="5" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtDepartmentName" Grid.Row="5" Text="{Binding DepartmentName, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Grid.Row="6" Grid.Column="2" Width="75" Height="23" HorizontalAlignment="Left" />
<Button x:Name="OKButton" Content="Save" Click="OKButton_Click" Grid.Row="6" Grid.Column="0" Width="75" Height="23" HorizontalAlignment="Left" />
</Grid>
Here the SaveUpdateEmp is object of propertyclass in model. How to validate these fields.??

You need to implement INotifyDataErrorInfo on your model and make sure that you have ValidatesOnDataErrors=True on the controls/properties that you need to validate. I can give you a code sample, but I think this does a better job than I can - http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx. If you have questions, I'm happy to answer.

Related

How to Instantiate an entire XAML Grid object in C#?

I'd like to instantiate an entire XAML Grid object in C#. My Grid object is a beast, it has 9 user-input fields, borders, labels and images.
I also want five instances of my Grid object, and I would like to instantiate them during run-time on the fly (with a press of a button). Is this possible? What is the best approach? Here is my Grid object...
<Grid Margin="2">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Row="1" Grid.Column="0" Grid.RowSpan="6" Grid.ColumnSpan="8" BorderBrush="Black" BorderThickness="1" CornerRadius="5">
<Label Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="8" Background="#505050" ></Label>
</Border>
<TextBlock Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="4" Text="TRANSFORM" TextAlignment="Center" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="8" Text="Position" VerticalAlignment="Bottom" TextAlignment="Left" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen" Margin="2"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="1" Text="x " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="4" Grid.ColumnSpan="1" Text="y " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="6" Grid.ColumnSpan="1" Text="z " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBox x:Name ="transform_x" Grid.Row="1" Grid.Column="3" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2" ></TextBox>
<TextBox x:Name ="transform_y" Grid.Row="1" Grid.Column="5" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2" ></TextBox>
<TextBox x:Name ="transform_z" Grid.Row="1" Grid.Column="7" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2" ></TextBox>
<TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="8" Text="Rotation" VerticalAlignment="Bottom" TextAlignment="Left" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen" Margin="2"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="1" Text="x " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="4" Grid.ColumnSpan="1" Text="y " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="6" Grid.ColumnSpan="1" Text="z " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBox x:Name ="rotation_x" Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
<TextBox x:Name ="rotation_y" Grid.Row="2" Grid.Column="5" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
<TextBox x:Name ="rotation_z" Grid.Row="2" Grid.Column="7" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
<TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="8" Text="Scale" VerticalAlignment="Bottom" TextAlignment="Left" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen" Margin="2"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="1" Text="x " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="4" Grid.ColumnSpan="1" Text="y " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="6" Grid.ColumnSpan="1" Text="z " VerticalAlignment="Bottom" TextAlignment="Right" FontSize="10" Foreground="#FD3777" FontFamily="./resources/#Pilsen"></TextBlock>
<TextBox x:Name ="scale_x" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
<TextBox x:Name ="scale_y" Grid.Row="3" Grid.Column="5" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
<TextBox x:Name ="scale_z" Grid.Row="3" Grid.Column="7" Grid.ColumnSpan="1" TextAlignment="Center" VerticalAlignment="Bottom" FontSize="10" Background="#707070" Foreground="Black" FontFamily="./resources/#Pilsen" Margin="2"></TextBox>
</Grid>
Simply new up a Grid in code
Grid grid = new Grid() { Margin = new Thickness(2) };
and add elements to it eg.
grid.Children.Add(new Border());
TextBlock t = new TextBlock();
t.SetValue(Grid.RowProperty, 0);
t.SetValue(Grid.ColumnProperty, 2);
grid.Children.Add(t);
//etc...
Or you could add a UserControl item to your project and put your Grid inside its xaml. Then you can new up as many MyGridControl's as you want.
You can do the following:
create a UserControl containing your grid, say MyBeastGrid
in your destination form have a placeholder where those instantiated grids should be placed, say MyPlaceholder
add a button (or other triggering mechanism that should add the MyBeastGrid to MyPlaceholder)
in the button's Click event handler you simply call MyPlaceholder.Children.Add(new MyBeastGrid());
If you need to pass some parameters to MyBeastGrid, define some public properties there and either provide parameterised constructor or call your grid with new MyBeastGrid() { Property1 = value1, Property2 = value2 };
I suggest you use ScrollViewer to store your MyBeastGrid instances as it provides scrolling out of the box.

Printing in UWP app - different layout on different devices

I've created printing solution for my XAML UWP MVVM application using example described on this link: https://xamlbrewer.wordpress.com/2016/10/25/a-recipe-for-printing-in-uwp-mvvm-apps/ (The source code is on the link: https://github.com/XamlBrewer/XamlBrewer.Uwp.PrintService )
Print preview that I get on my laptop is different than the one I get on the toughbook Panasonic CF-20. On the thoughbook layout gets messed up.
On the laptop (looks exactly the same on several laptops/PCs):
laptop_print
On the thoughbook:
thoughbook_print
My report page (page I use for preview/printing):
<Page
x:Class="WK.Drf.FrontOffice.App.UI.DossierHandling.HandoverPrintReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WK.Drf.FrontOffice.App.UI.DossierHandling"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<RichTextBlock Height="640" VerticalAlignment="Bottom">
<Paragraph TextAlignment="Left" Margin ="55,0,0,0">
<Run Text="Overdracht" FontSize="30" FontWeight="Bold" />
<LineBreak />
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="WrapWholeWords" FontWeight="Bold" Grid.Column="1" Grid.Row="0">RAV Kennemerland</TextBlock>
<TextBlock Text="{Binding AmbulanceNumber}" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="1" />
<TextBlock Text="{Binding ParamedicCode}" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="2" />
<TextBlock Text="{Binding DriverCode}" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="3" />
<TextBlock Text="{Binding ThirdPersonCode}" TextWrapping="WrapWholeWords" Grid.Column="1" Grid.Row="4" />
<TextBlock Text="{Binding PatientName}" TextWrapping="WrapWholeWords" FontWeight="Bold" Grid.Column="2" Grid.Row="0" />
<TextBlock Text="{Binding PatientDateOfBirth}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" />
<TextBlock Text="{Binding PatientAddress1}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" />
<TextBlock Text="{Binding PatientAddress2}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="3" />
<TextBlock Text="{Binding PatientBsn}" TextWrapping="WrapWholeWords" Grid.Column="3" Grid.Row="0" />
<TextBlock Text="{Binding PatientInsuranceCompany}" TextWrapping="WrapWholeWords" Grid.Column="3" Grid.Row="1"/>
<TextBlock Text="{Binding PatientInsuranceNo}" TextWrapping="WrapWholeWords" Grid.Column="3" Grid.Row="2" />
<TextBlock Text="{Binding PatientEmail}" TextWrapping="WrapWholeWords" Grid.Column="3" Grid.Row="3" />
<TextBlock Text="{Binding PatientPhoneNumber}" TextWrapping="WrapWholeWords" Grid.Column="3" Grid.Row="4" />
<TextBlock TextWrapping="WrapWholeWords" FontWeight="Bold" Grid.Column="4" Grid.Row="0" />
<TextBlock TextWrapping="WrapWholeWords" Grid.Column="4" Grid.Row="1" />
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="1" Fill="DarkGray"></Rectangle>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" FontWeight="Bold" Grid.Column="0" Grid.RowSpan="8" TextAlignment="Left">S</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold" Visibility="{Binding Accident, Converter={StaticResource StringToVis}}">Ongeval:</TextBlock>
<TextBlock Text="{Binding Accident}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="0" Visibility="{Binding Accident, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Visibility="{Binding AmpleEvents, Converter={StaticResource StringToVis}}">Situatie:</TextBlock>
<TextBlock Text="{Binding AmpleEvents}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" Visibility="{Binding AmpleEvents, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Visibility="{Binding AirwayS, Converter={StaticResource StringToVis}}">A:</TextBlock>
<TextBlock Text="{Binding AirwayS}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" Visibility="{Binding AirwayS, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Visibility="{Binding BreathingS, Converter={StaticResource StringToVis}}">B:</TextBlock>
<TextBlock Text="{Binding BreathingS}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="3" Visibility="{Binding BreathingS, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Visibility="{Binding CirculationS, Converter={StaticResource StringToVis}}">C:</TextBlock>
<TextBlock Text="{Binding CirculationS}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="4" Visibility="{Binding CirculationS, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="5" FontWeight="Bold" Visibility="{Binding DisabilityS, Converter={StaticResource StringToVis}}">D:</TextBlock>
<TextBlock Text="{Binding DisabilityS}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="5" Visibility="{Binding DisabilityS, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="6" FontWeight="Bold" Visibility="{Binding ExposureS, Converter={StaticResource StringToVis}}">E:</TextBlock>
<TextBlock Text="{Binding ExposureS}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="6" Visibility="{Binding ExposureS, Converter={StaticResource StringToVis}}"/>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="1" Fill="DarkGray"></Rectangle>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" FontWeight="Bold" Grid.Column="0" Grid.RowSpan="6" TextAlignment="Left">B</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold" Visibility="{Binding Allergy, Converter={StaticResource StringToVis}}">Allergie:</TextBlock>
<TextBlock Text="{Binding Allergy}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="0" Visibility="{Binding Accident, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Visibility="{Binding Medication, Converter={StaticResource StringToVis}}">Medicatie:</TextBlock>
<TextBlock Text="{Binding Medication}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" Visibility="{Binding Medication, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Visibility="{Binding PastIllnesses, Converter={StaticResource StringToVis}}">Verleden ziekten:</TextBlock>
<TextBlock Text="{Binding PastIllnesses}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" Visibility="{Binding PastIllnesses, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Visibility="{Binding Insulation, Converter={StaticResource StringToVis}}">Isolatie:</TextBlock>
<TextBlock Text="{Binding Insulation}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="3" Visibility="{Binding Insulation, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Visibility="{Binding InfectionRisk, Converter={StaticResource StringToVis}}">Besmettingsrisico:</TextBlock>
<TextBlock Text="{Binding InfectionRisk}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="4" Visibility="{Binding InfectionRisk, Converter={StaticResource StringToVis}}"/>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="1" Fill="DarkGray"></Rectangle>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" FontWeight="Bold" Grid.Column="0" Grid.RowSpan="8" TextAlignment="Left">A</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" FontSize="20" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Bevindingen</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Hoofd en gelaat:</TextBlock>
<TextBlock Text="{Binding HeadAndFace}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Nek/Hals/CWK:</TextBlock>
<TextBlock Text="{Binding Neck}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Rug:</TextBlock>
<TextBlock Text="{Binding Back}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="3" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Thorax:</TextBlock>
<TextBlock Text="{Binding Thorax}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="4" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="5" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Arm:</TextBlock>
<TextBlock Text="{Binding Arms}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="5" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="6" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Abdomen:</TextBlock>
<TextBlock Text="{Binding Abdomen}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="6" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="7" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Bekken:</TextBlock>
<TextBlock Text="{Binding Pelvis}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="7" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="8" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Been:</TextBlock>
<TextBlock Text="{Binding Legs}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="8" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="9" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Uitscheiding:</TextBlock>
<TextBlock Text="{Binding Secreteion}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="9" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="10" FontWeight="Bold" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}">Verloskundig:</TextBlock>
<TextBlock Text="{Binding Gynecology}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="10" Visibility="{Binding HeadAndFace, Converter={StaticResource StringToVis}}"/>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" Grid.Row="0" FontSize="20" Visibility="{Binding TreatmentSectionVisibility}">Behandeling</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Visibility="{Binding AirwayT, Converter={StaticResource StringToVis}}">A:</TextBlock>
<TextBlock Text="{Binding AirwayT}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" Visibility="{Binding AirwayT, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Visibility="{Binding BreathingT, Converter={StaticResource StringToVis}}">B:</TextBlock>
<TextBlock Text="{Binding BreathingT}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" Visibility="{Binding BreathingT, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Visibility="{Binding CirculationT, Converter={StaticResource StringToVis}}">C:</TextBlock>
<TextBlock Text="{Binding CirculationT}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="3" Visibility="{Binding CirculationT, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Visibility="{Binding DisabilityT, Converter={StaticResource StringToVis}}">D:</TextBlock>
<TextBlock Text="{Binding DisabilityT}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="4" Visibility="{Binding DisabilityT, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="5" FontWeight="Bold" Visibility="{Binding ExposureT, Converter={StaticResource StringToVis}}">E:</TextBlock>
<TextBlock Text="{Binding ExposureT}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="5" Visibility="{Binding ExposureT, Converter={StaticResource StringToVis}}"/>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Height="1" Fill="DarkGray"></Rectangle>
</Grid>
</InlineUIContainer>
</Paragraph>
<Paragraph>
<InlineUIContainer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" FontWeight="Bold" Grid.Column="0" Grid.RowSpan="6" TextAlignment="Left">R</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" FontSize="20" Visibility="{Binding AdditionalExplanation, Converter={StaticResource StringToVis}}">Verklaring Geen Vervoer</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Visibility="{Binding AdditionalExplanation, Converter={StaticResource StringToVis}}">Reden:</TextBlock>
<TextBlock Text="{Binding AdditionalExplanation}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="1" Visibility="{Binding AdditionalExplanation, Converter={StaticResource StringToVis}}"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Visibility="{Binding AdditionalExplanationText, Converter={StaticResource StringToVis}}">Toelichting:</TextBlock>
<TextBlock Text="{Binding AdditionalExplanationText}" TextWrapping="WrapWholeWords" Grid.Column="2" Grid.Row="2" Visibility="{Binding AdditionalExplanationText, Converter={StaticResource StringToVis}}"/>
</Grid>
</InlineUIContainer>
</Paragraph>
</RichTextBlock>
</Page>
What should I fix to get normal looking print layout on the thoughbook?
I've managed to fix my solution - I've put all of the TextBlocks inside of the Border with Padding="0" Margin="0" and now everything looks nice on the laptop and toughbook as well:
<Border Padding="0" Margin="0" Grid.Column="0" Grid.Row="1">
<TextBlock Padding="0" Margin="0" Text="{Binding AmbulanceNumber}"
TextWrapping="WrapWholeWords"/>
</Border>

Expanding selected row in gridview on WEH8.1

I am currently developing an application for Windows Embedded Handheld 8.1 and have run into an issue where I have a dynamically expanding grid inside a gridview. My problem is that since this application runs on handheld devices I have a very limited space to use on every row.
What I would like to do is to just show general information on each row and then when a row is tapped or selected in the device, I would like to somehow expand that specific row and show some more detailed information, this seems to be problematic however since as soon as I start messing with a specific rows height, every other row in the ItemTemplate naturally also grows, leaving a lot of blank spaces in the grid.
Normally I would have used a DataGrid and DataGrid.RowDetailsTemplate, but that control does not seem to be implemented in WEH8.1.
So my question is if someone has a solution or possibly a workaround to my problem?
Code Example on GridView Below:
<ScrollViewer Grid.Row="1" Margin="0">
<GridView x:Name="gvCustomerOrderRows">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Background="{Binding BackgroundColor}" Margin="0" Height="{Binding ShowSecondRowHeight}" Tapped="Grid_Tapped" Tag="{Binding kor_row}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="31.25"/>
<ColumnDefinition Width="58.75"/>
<ColumnDefinition Width="105"/>
<ColumnDefinition Width="65"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="70"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding kor_pos}" Grid.Row="0" Visibility="{Binding VisibilityHideThenText}" Grid.Column="0" FontSize="14" VerticalAlignment="Center" Margin="0,17,0,16"></TextBlock>
<TextBlock Text="{Binding kor_partno}" Grid.Row="0" Visibility="{Binding VisibilityHideThenText}" Grid.Column="1" FontSize="14" VerticalAlignment="Center" Margin="0,17,0,16" Grid.ColumnSpan="2" ></TextBlock>
<TextBlock Text="{Binding kor_txt}" Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" FontSize="14" VerticalAlignment="Center" MaxLines="2" TextWrapping="Wrap"/>
<TextBlock Text="{Binding kor_rqty}" Grid.Row="0" Visibility="{Binding VisibilityHideThenText}" Grid.Column="5" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" TextAlignment="Center"></TextBlock>
<TextBox x:Name="txtQuantity" Grid.Row="0" Text="{Binding rep_qty, Mode=TwoWay}" Visibility="{Binding VisibilityHideThenText}" Background="{Binding DeliverColor, Mode=TwoWay}" BorderBrush="{Binding DeliverColor, Mode=TwoWay}" InputScope="Number" TextAlignment="Right" Grid.Column="6" GotFocus="txtQuantity_GotFocus" Margin="6,10,-1,0" Height="39"/>
<TextBlock Text="{Binding kor_ldat}" Grid.Row="1" Visibility="{Binding VisibilityHideThenText}" Grid.Column="1" Grid.ColumnSpan="2" FontSize="14" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left"></TextBlock>
<TextBlock Text="Stock Loc.: " Grid.Row="1" Grid.Column="3" TextAlignment="Right" VerticalAlignment="Top" FontSize="14" Visibility="{Binding VisibilityHideThenText}"></TextBlock>
<TextBlock Grid.Row="1" Visibility="{Binding VisibilityHideThenText}" Tag="{Binding kor_row}" Grid.Column="4" Grid.ColumnSpan="2" VerticalAlignment="Top" FontWeight="Bold" FontSize="14" Tapped="TextBlock_Tapped" Margin="10,0,0,0"><Underline><Run Text="{Binding SelectedLocation, Mode=TwoWay}"/> </Underline></TextBlock>
<TextBlock Text="{Binding LocQuantity}" Grid.Row="1" Grid.Column="5" VerticalAlignment="Top" Visibility="{Binding VisibilityHideThenText}" FontSize="14" TextAlignment="Center"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</ScrollViewer>

ScrollViewer doesn't work on Surface 4 - WPF C#

I am creating an application in WPF ( C # ).
And here's my problem, when the test on the surface 4 , with the stylus the ScrollViewer does not work , that does not scroll .
But it is clear that if I try with your finger , the finger works . It ' possible that the surface pen should be treated differently from windows? how can I fix this small , but huge problem ?
Here is my code , it works with your finger scroll , with the surface 4 no pen. Help :)
<ScrollViewer x:Name="listPastMeetinsVisibility" Grid.Column="0" Grid.Row="0" Margin="15,36,15,35" Background="GhostWhite" VerticalScrollBarVisibility="Hidden" PanningMode="Both">
<ItemsControl ItemsSource="{Binding Path=PastMeetingList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<surface:SurfaceButton Tag="{Binding MID}" Click="Meeting_Click">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="118"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="#DDD" BorderThickness="0,0,0,1"></Border>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="28" Margin="20,5,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastDayString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" Text="{Binding PastMonthString}" FontSize="12" Margin="8,37,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" Text="{Binding StartDate.Year}" FontSize="12" Margin="37,37,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Width="28" FontSize="12" Height="Auto" Margin="85,12,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastDayOfWeekString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="75,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastHourString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="91,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text=":"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="95,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastMinuteString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Subject}" FontWeight="Bold" FontSize="14" Margin="20,14,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Subject}" FontSize="13" Margin="20,33,0,0"/>
<Image Grid.Row="0" Visibility="{Binding Presence, Converter={StaticResource booleanToVisibilityConverter}}" Grid.Column="1" Source="/Resources/Images/icon-presence.png" Margin="0,0,7,0" Width="24" HorizontalAlignment="Right"></Image>
</Grid>
</StackPanel>
</ControlTemplate>
</Button.Template>
</surface:SurfaceButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
I solved in this way :
1 - download from NuGet Microsoft.Surface : https://www.nuget.org/packages/Microsoft.Surface/
2 - add the assembly to the xaml :
xmlns:surface = "http://schemas.microsoft.com/surface/2008"
3 - change the ScrollViewer with surface:SurfaceScrollViewer
updated code with SurfaceScrollViewer :
<surface:SurfaceScrollViewer x:Name="listPastMeetinsVisibility" Grid.Column="0" Grid.Row="0" Margin="15,36,15,35" Background="GhostWhite" VerticalScrollBarVisibility="Hidden" PanningMode="Both">
<ItemsControl ItemsSource="{Binding Path=PastMeetingList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Tag="{Binding MID}" Click="Meeting_Click">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="118"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="#DDD" BorderThickness="0,0,0,1"></Border>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="28" Margin="20,5,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastDayString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" Text="{Binding PastMonthString}" FontSize="12" Margin="8,37,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" Text="{Binding StartDate.Year}" FontSize="12" Margin="37,37,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Width="28" FontSize="12" Height="Auto" Margin="85,12,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastDayOfWeekString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="75,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastHourString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="91,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text=":"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="95,33,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding PastMinuteString}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Subject}" FontWeight="Bold" FontSize="14" Margin="20,14,0,0"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Light}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Subject}" FontSize="13" Margin="20,33,0,0"/>
<Image Grid.Row="0" Visibility="{Binding Presence, Converter={StaticResource booleanToVisibilityConverter}}" Grid.Column="1" Source="/Resources/Images/icon-presence.png" Margin="0,0,7,0" Width="24" HorizontalAlignment="Right"></Image>
</Grid>
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</surface:SurfaceScrollViewer>
Enjoy the Stylus pen on surface scrollviewer :)

User Control Not Rendering When Used as a DataTemplate?

I have a usercontrol which I want to use as a DataTemplate in a Listbox.
This works:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If I put the exact same code from between the <DataTemplate> tags:
<UserControl x:Class="CandiMan.View.CandidatePresentationControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cm="clr-namespace:CandiMan;assembly=CandiMan"
xmlns:vw="clr-namespace:CandiMan.View;assembly=CandiMan"
xmlns:vm="clr-namespace:CandiMan.ViewModel;assembly=CandiMan"
Height="100" Width="880" BorderBrush="Black" BorderThickness="1">
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</UserControl>
into a usercontrol named CandidatePresentationControl and do it like
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
it does not get rendered. No errors, just an empty listbox. Can someone help me??
Thank you!
edit: I forgot something, dunno if it matters: The whole thing I'm doing this in, is a usercontrol, too.
It shouldn't matter, that your referenced UserControl is within another UserControl. Try these steps to better debug your XAML-code: http://beacosta.com/blog/?p=52
Since you have your data hard wired in XAML, the only way to explain the empty ListBox is, that your UserControl can't be found by the parent UserControl, imo.
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl DataContext="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You have to write this way in order to bind datacontext, I would suggest you look at MVVM that will give you idea on how to do it even better way.

Categories

Resources