ScrollViewer XAML : MouseWheel Not Working - c#

I'm developing an application for a small business and I have a problem with the Horizontal Scroll Viewer.
Horizontal ScrollViewer appears on the screen but the mouse wheel doesn't work.
I Have this XAML Code:
<ScrollViewer ScrollViewer.ZoomMode="Disabled" HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto" ScrollViewer.IsHorizontalScrollChainingEnabled="True" VerticalScrollBarVisibility="Disabled" Margin="0,130,0,0" VerticalContentAlignment="Stretch" ManipulationMode="All">
<Grid Width="1000" HorizontalAlignment="Left" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250*" ></ColumnDefinition>
<ColumnDefinition Width="250*"/>
<ColumnDefinition Width="250*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="65*" />
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="45*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,0,0,0" Text="Στοιχεία Πελάτη" FontSize="50"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Όνομα :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Επώνυμο :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Τηλέφωνο :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="4" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Κινητό :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Διεύθυνση :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Πόλη :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="2" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Χώρα :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Email :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="2" Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Α.Φ.Μ :" FontSize="30"></TextBlock>
<TextBlock Grid.Column="2" Grid.Row="4" HorizontalAlignment="Right" VerticalAlignment="Center" Text="ΔΟΥ:" FontSize="30"></TextBlock>
<TextBlock Grid.Column="2" Grid.Row="5" HorizontalAlignment="Right" VerticalAlignment="Center" Text="Περιγραφή:" FontSize="30"></TextBlock>
<TextBox Grid.Column="1" Grid.Row="1" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="2" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="3" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="4" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="5" Height="30"></TextBox>
<TextBox Grid.Column="1" Grid.Row="6" Height="30"></TextBox>
<TextBox Grid.Column="3" Grid.Row="1" Height="30"></TextBox>
<TextBox Grid.Column="3" Grid.Row="2" Height="30"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Height="30"></TextBox>
<TextBox Grid.Column="3" Grid.Row="4" Height="30" VerticalAlignment="Center"></TextBox>
<TextBox Grid.Column="3" Grid.Row="5" Grid.RowSpan="4" AcceptsReturn="True" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
<Button Grid.Column="3" Grid.Row="9" Content="Αποθήκευση" FontSize="22" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Button>
</Grid>
</ScrollViewer>
What could be wrong?

In addition to making sure your scrollviewer is being presented at a fixed width, therefore enabling scrolling within the viewer itself (it currently looks like the viewer doesn't need to scroll to display the content), change the viewer declaration to the following.
<ScrollViewer
Style="{StaticResource HorizontalScrollViewerStyle}"
ScrollViewer.IsHorizontalScrollChainingEnabled="True"
Margin="0,130,0,0"
VerticalContentAlignment="Stretch"
ManipulationMode="All">
The style should be defined in StandardStyles.xaml, but if you aren't using that file, the definition is as follows.
<Style x:Key="HorizontalScrollViewerStyle" TargetType="ScrollViewer">
<Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
</Style>

Try reducing the grid width and then check. Usually, if grid width is large or 'auto' the content automatically scales to fit and hence scrollviewer doesn't work.

Related

How to Pass data from one UserControl1 to UserControl2 from a button in UserControl1 WPF MVVM

I recently started studying about User Controls. I have a Main Window which contains this 2 User Controls. UserControl1 is a form to get the data, and when the submit button is clicked in UserControl1, the UserControl2 will be visible viewing the data send from the UserControl1.
Here is my MainWindow xaml (HomeCareMain.xaml)
<Window x:Class="PatientRecordMVVM.Views.HomeCareMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
FontFamily="{materialDesign:MaterialDesignFont}"
xmlns:local="clr-namespace:PatientRecordMVVM.Views"
mc:Ignorable="d"
Title="HomeCareMain" Height="850" Width="1500" Foreground="White">
<Window.Resources>
<Storyboard x:Key="MenuOpen">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridSideMenu">
<EasingDoubleKeyFrame KeyTime="0" Value="60"/>
<EasingDoubleKeyFrame KeyTime="0:0:0:0" Value="210"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="MenuClose">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridSideMenu">
<EasingDoubleKeyFrame KeyTime="0" Value="210"/>
<EasingDoubleKeyFrame KeyTime="0:0:0:0" Value="60"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonOpenMenu">
<BeginStoryboard Storyboard="{StaticResource MenuOpen}"/>
</EventTrigger>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonCloseMenu">
<BeginStoryboard Storyboard="{StaticResource MenuClose}"/>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="8*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="25*"/>
</Grid.RowDefinitions>
<Image x:Name="Logo" Grid.Row="1" Grid.ColumnSpan="3" Source="/PatientRecordMVVM;component/Images/logo.jpg" Opacity="0.12" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Grid Grid.Row="0" Grid.ColumnSpan="3" Height="60" VerticalAlignment="Top" Background="#2c8a93">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Image Source="/PatientRecordMVVM;component/Images/logo.jpg" Width="30" Height="30" Margin="0,0,20,0"/>
<TextBlock Text="HOME CARE" FontSize="22" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<materialDesign:PopupBox PlacementMode="BottomAndAlignRightEdges" StaysOpen="False" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10">
<StackPanel Width="150">
<Button Content="Settings"/>
<Separator/>
<Button Command="{Binding Path=LogoutCommand}" Content="Logout"/>
</StackPanel>
</materialDesign:PopupBox>
</Grid>
<Grid x:Name="GridSideMenu" Grid.RowSpan="2" Grid.Column="0" Width="210" HorizontalAlignment="Left" Background="#1f3e66">
<StackPanel Orientation="Vertical">
<Grid Height="60" VerticalAlignment="Top">
<Button x:Name="ButtonCloseMenu" Background="{x:Null}" BorderBrush="{x:Null}" Width="60" Height="60" HorizontalAlignment="Right" Visibility="Collapsed" Click="ButtonCloseMenu_Click">
<materialDesign:PackIcon Kind="ArrowLeft" Width="25" Height="25"/>
</Button>
<Button x:Name="ButtonOpenMenu" Background="{x:Null}" BorderBrush="{x:Null}" Width="60" Height="60" HorizontalAlignment="Right" Click="ButtonOpenMenu_Click">
<materialDesign:PackIcon Kind="Menu" Width="25" Height="25"/>
</Button>
</Grid>
<ListView Foreground="White" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListViewItem Height="60">
<Button Command="{Binding Path=AddPatientCommand}" CommandParameter="{Binding ElementName=AddPatient}" Background="#1f3e66" BorderBrush="#1f3e66" Width="190" Height="40" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="Add" Foreground="White" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="-5,0,20,0"/>
<TextBlock Text="Add Patient Details" FontSize="12" VerticalAlignment="Center" Margin='0,0,20,0'/>
</StackPanel>
</Button>
</ListViewItem>
</ListView>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Grid.ColumnSpan="3">
<local:AddPatientRecordDetails
x:Name="AddPatient"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Width="800"
Height="730"
Margin="0,0,20,0"
/>
</Grid>
<Grid Grid.Row="1" Grid.Column="2">
<local:PrintPreviewControl
x:Name="PrintPreview"
HorizontalAlignment="Center"
Width="600"
Height="700"
/>
</Grid>
</Grid>
</Window>
This is UserControl1 xaml (AddPatientRecordDetails.xaml)
<UserControl x:Class="PatientRecordMVVM.Views.AddPatientRecordDetails"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
FontFamily="{materialDesign:MaterialDesignFont}"
xmlns:local="clr-namespace:PatientRecordMVVM.Views"
mc:Ignorable="d"
d:DesignHeight="850" d:DesignWidth="600" Background="Transparent" BorderBrush="#58af9d" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2.5*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1.5*"/>
<RowDefinition Height="1.5*"/>
<RowDefinition Height="18*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2" Grid.ColumnSpan="3" Background="#2c8a93"/>
<!--Patient Id block-->
<StackPanel Grid.ColumnSpan="2" Style="{StaticResource StackpanelStyle}">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Patient ID :
</Label>
<Label Content="{Binding Path=GuidGenerator}" FontSize="16" Foreground="White" Margin="5,0"/>
</StackPanel>
<!--Date block-->
<StackPanel Grid.ColumnSpan="3" Style="{StaticResource StackpanelStyle}" HorizontalAlignment="Right">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Date :
</Label>
<Label Name="date_time" Content="{Binding Path=CurrentDate}" FontSize="16" Foreground="White" Margin="5,0"/>
</StackPanel>
<!--Title block-->
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" FontSize="20" FontWeight="Bold" Foreground="White" TextDecorations="Underline" HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="200">
Patient Registration Information
</TextBlock>
<!--Main sub Grid-->
<Grid Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="25,25,25,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="200*" MinWidth="158" MaxWidth="190" />
<ColumnDefinition Width="700*" MaxWidth="600" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="2.95*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!--Name block-->
<Label Grid.Row="0" Grid.Column="1" Style="{StaticResource LabelStyles}">Name :</Label>
<TextBox Name="fName" Grid.Row="0" Grid.Column="2" Text="{Binding Path = PatientName}" Style="{StaticResource TextBoxStyle}"/>
<!--Address block-->
<Label Grid.Row="1" Grid.Column="1" Style="{StaticResource LabelStyles}" VerticalAlignment="Top" Margin="0,7,15,0">Address :</Label>
<StackPanel Grid.Row="1" Grid.Column="2" Orientation="Vertical" VerticalAlignment="Center" Margin="0,2">
<DockPanel LastChildFill="True" Margin="0,5">
<Label Style="{StaticResource AddressLabelStyles}" HorizontalAlignment="Right">Number :</Label>
<TextBox Name="Number" Text="{Binding Path = PatientAddress.Number}" Style="{StaticResource TextBoxStyle}"/>
</DockPanel>
<DockPanel LastChildFill="True" Margin="0,5">
<Label Style="{StaticResource AddressLabelStyles}" Margin="12,0">Street :</Label>
<TextBox Name="Street" Text="{Binding Path = PatientAddress.Street}" Style="{StaticResource TextBoxStyle}" Margin="3,0,0,0" />
</DockPanel>
<DockPanel LastChildFill="True" Margin="0,5">
<Label Style="{StaticResource AddressLabelStyles}" Margin="24,0">City :</Label>
<TextBox Name="City" Text="{Binding Path = PatientAddress.City}" Style="{StaticResource TextBoxStyle}" Margin="-9,0,0,0"/>
</DockPanel>
</StackPanel>
<!--Gender block-->
<Label Grid.Row="2" Grid.Column="1" Style="{StaticResource LabelStyles}">Gender :</Label>
<StackPanel Grid.Row="2" Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,6,0,0">
<RadioButton Name="male" Command="{Binding Path=GetPatientGenderCommand}" CommandParameter="{Binding ElementName=male, Path=Content}" Content="Male" FontSize="14" Foreground="Black" Padding="5,-2.5" MinWidth="100"/>
<RadioButton Name="female" Command="{Binding Path=GetPatientGenderCommand}" CommandParameter="{Binding ElementName=female, Path=Content}" Content="Female" FontSize="14" Foreground="Black" Padding="5,-2.5"/>
</StackPanel>
<!--Birthdate block-->
<Label Grid.Row="3" Grid.Column="1" Style="{StaticResource LabelStyles}">Birthdate :</Label>
<DatePicker Name="Date" Grid.Row="3" Grid.Column="2" SelectedDate ="{Binding Path = PatientDateOfBirth}" Style="{StaticResource TextBoxStyle}" MaxHeight="30" Padding="1"/>
<!--Age block-->
<Label Grid.Row="4" Grid.Column="1" Style="{StaticResource LabelStyles}">Age :</Label>
<TextBox Name="Age" Grid.Row="4" Grid.Column="2" Text="{Binding Path = PatientAge}" Style="{StaticResource TextBoxStyle}"/>
<!--Image block-->
<Label Grid.Row="5" Grid.Column="1" Style="{StaticResource LabelStyles}">Image :</Label>
<DockPanel Grid.Row="5" Grid.Column="2" LastChildFill="True" VerticalAlignment="Center" MinHeight="30">
<Button DockPanel.Dock="Left" Command="{Binding Path=GetPatientImageCommand, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource ButtonStyle}" Content="Browse" Margin="0,0,5,0"/>
<TextBox Name="FileBrowser" DockPanel.Dock="Right" Text="{Binding Path= PatientImageSource}" Style="{StaticResource TextBoxStyle}" HorizontalAlignment="Stretch"/>
</DockPanel>
<!--Image view block-->
<Image Name="ImageViewer" Grid.Row="6" Grid.Column="2" Source ="{Binding Path= PatientImageSource}" HorizontalAlignment="Left" MinWidth="95" MaxWidth="150" MinHeight="95" MaxHeight="150" Margin="0,0,0,10"/>
<!--Department block-->
<Label Grid.Row="7" Grid.Column="1" Style="{StaticResource LabelStyles}">Department :</Label>
<ComboBox Name="Department" Grid.Row="7" Grid.Column="2" ItemsSource="{Binding Department}" SelectedItem="{Binding Path = PatientDepartment}" FontSize="14" Foreground="Black" BorderBrush="LightGray" BorderThickness="1" VerticalAlignment="Center" MinHeight="30"/>
<!--Ward Block-->
<Label Grid.Row="8" Grid.Column="1" Style="{StaticResource LabelStyles}">Ward :</Label>
<ComboBox Name="Ward" Grid.Row="8" Grid.Column="2" ItemsSource="{Binding Ward}" SelectedItem="{Binding Path = PatientWard}" FontSize="14" Foreground="Black" BorderBrush="LightGray" BorderThickness="1" VerticalAlignment="Center" MinHeight="30"/>
<!--Doctor Block-->
<Label Grid.Row="9" Grid.Column="1" Style="{StaticResource LabelStyles}">Doctor In Charge :</Label>
<ComboBox Name="Doctor" Grid.Row="9" Grid.Column="2" ItemsSource="{Binding DocInCharge}" SelectedItem="{Binding Path = PatientDotorcInCharge}" FontSize="14" Foreground="Black" BorderBrush="LightGray" BorderThickness="1" VerticalAlignment="Center" MinHeight="30"/>
</Grid>
<!--Buttons Section-->
<StackPanel Grid.Row="3" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20,10,26,0" >
<Button Command="{Binding Path=PreviewCommand}" Style="{StaticResource ButtonStyle}" Content="Print Preview" Margin="0,0,5,0"/>
<Button Command="{Binding Path=ClearPatientCommand}" Style="{StaticResource ButtonStyle}" Content="Clear"/>
</StackPanel>
</Grid>
</UserControl>
This is my UserControl2 (PrintPreviewControl.xaml)
<UserControl x:Class="PatientRecordMVVM.Views.PrintPreviewControl"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
FontFamily="{materialDesign:MaterialDesignFont}"
xmlns:local="clr-namespace:PatientRecordMVVM.Views"
mc:Ignorable="d"
d:DesignHeight="850" d:DesignWidth="800" Background="White">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<!--Main Sub Grid 1-->
<Grid x:Name="MainSubGrid" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2.5*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height ="1.5*"/>
<RowDefinition Height ="1.5*"/>
<RowDefinition Height ="6.5*"/>
<RowDefinition Height ="7*"/>
<RowDefinition Height ="6*"/>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2" Grid.ColumnSpan="3" Background="#58af9d"/>
<!--Patient Id block-->
<StackPanel Grid.ColumnSpan="2" Style="{StaticResource StackpanelStyle}">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Patient ID :
</Label>
<Label Content="{Binding PatientID}" FontSize="16" Foreground="White" Margin="5,0,0,0"/>
</StackPanel>
<!--Date block-->
<StackPanel Grid.ColumnSpan="3" Style="{StaticResource StackpanelStyle}" HorizontalAlignment="Right">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Date :
</Label>
<Label Name="date_time" Content="{Binding PatientRegisteredDate}" FontSize="16" Foreground="White" Margin="5,0"/>
</StackPanel>
<!--Title block-->
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" FontSize="20" FontWeight="Bold" Foreground="White" TextDecorations="Underline" HorizontalAlignment="Center" VerticalAlignment="Center">
Patient Registration Information
</TextBlock>
<!--Sub grid 1-->
<Grid Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" Margin="25,10,25,20">
<!--User's image View and name-->
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Ellipse Width="150" Height="150">
<Ellipse.Fill>
<ImageBrush x:Name="ImageViewer2" ImageSource="{Binding PatientImageSource}"/>
</Ellipse.Fill>
</Ellipse>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,10">
<Label Style="{StaticResource LabelStyles}" Margin="0">Patient Name :</Label>
<TextBlock x:Name="ViewName" Text="{Binding PatientName}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
</StackPanel>
</Grid>
<!--Sub grid 2-->
<GroupBox Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="25,-35,25,0">
<GroupBox.Header>
<TextBlock Style="{StaticResource TextBlockStyleControl}">Patient Personal Information</TextBlock>
</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="500*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5*"/>
<RowDefinition Height="3*" MaxHeight="80"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}" >Address :</Label>
<TextBlock x:Name="ViewANum" Text="{Binding PatientAddress.Number}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock x:Name="ViewAStrt" Text="{Binding PatientAddress.Street}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock x:Name="ViewACity" Text="{Binding PatientAddress.City}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,10">
<Label Style="{StaticResource PreviewLabelStyles}">Gender :</Label>
<TextBlock x:Name="ViewGender" Text="{Binding PatientGender}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Date of Birth :</Label>
<TextBlock x:Name="ViewDob" Text="{Binding PatientDateOfBirth}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Age :</Label>
<TextBlock x:Name="ViewAge" Text="{Binding PatientAge}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
</Grid>
</GroupBox>
<!--Sub grid 3-->
<GroupBox Grid.Row="4" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="25,0,25,0">
<GroupBox.Header>
<TextBlock Style="{StaticResource TextBlockStyleControl}">Patient Medical Information</TextBlock>
</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="500*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Department :</Label>
<TextBlock x:Name="ViewDepartment" Text="{Binding PatientDepartment}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,0">
<Label Style="{StaticResource PreviewLabelStyles}">Ward :</Label>
<TextBlock x:Name="ViewWard" Text="{Binding PatientWard}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Vertical" Margin="10,5,10,10">
<Label Style="{StaticResource PreviewLabelStyles}">Doctor in Charge :</Label>
<TextBlock x:Name="ViewDoc" Text="{Binding PatientDotorcInCharge}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
</Grid>
</GroupBox>
</Grid>
<StackPanel Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20,10,26,0">
<Button Command="{Binding Path=DefaultPrintCommand}" CommandParameter="{Binding ElementName=MainSubGrid}" Style="{StaticResource ButtonStyle}" Content="Default Print" Margin="0,0,5,0"/>
<Button Command="{Binding Path=ConfigureAndPrintCommand}" CommandParameter="{Binding ElementName=MainSubGrid}" Style="{StaticResource ButtonStyle}" Content="Configure Print"/>
</StackPanel>
</Grid>
</UserControl>
This is the Button Command of the UserControl1 in its ViewModel
#region Handlers : Commands
private void OnPreviewCommandExecute()
{
PatientRecordDetailsModel getPatientDetails = PopulatePatientDetails();
}
I didn't put the whole code inside the ViewModel since it's too long.
PatientRecordDetailsModel is the model object that will be sent to the UserControl2.
Inside the UserControl2 ViewModel constructor it binds the data with the userControl View.
class PrintPreviewViewModel
{
#region Fields
private IWindowService m_windowService;
private PatientRecordDetailsModel patient;
#endregion
#region Constructors
public PrintPreviewViewModel(PatientRecordDetailsModel patient)
{
this.patient = patient;
PatientID = patient.PatientId;
PatientRegisteredDate = patient.PatientRegisteredDate;
PatientName = patient.PatientName;
PatientAddress = patient.PatientAddress;
PatientGender = patient.PatientGender;
PatientDateOfBirth = patient.PatientDateOfBirth.ToShortDateString();
PatientAge = patient.PatientAge;
PatientImageSource = patient.PatientImageSource;
PatientDepartment = patient.PatientDepartment;
PatientWard = patient.PatientWard;
PatientDotorcInCharge = patient.PatientDoctorInCharge;
m_windowService = new WindowService();
}
}
Inside the HomeCareMain.xaml.cs file I defined a method called PrintPreviewButtonClicked() to bind the data to the UserControl2's DataContext and to Visible it.
public partial class HomeCareMain : Window
{
public HomeCareMain()
{
InitializeComponent();
this.DataContext = new HomeCareMainViewModel();
PatientRecordDetailsViewModel patientRecordDetailsViewModel = new PatientRecordDetailsViewModel();
AddPatient.DataContext = patientRecordDetailsViewModel;
AddPatient.Visibility = Visibility.Hidden;
PrintPreview.Visibility = Visibility.Hidden;
}
public void PrintPreviewButtonClicked(PatientRecordDetailsModel patient)
{
PrintPreview.DataContext = new PrintPreviewViewModel(patient);
PrintPreview.Visibility = Visibility.Visible;
}
}
The problem is I want to send the PatientRecordDetailsModel object to the HomeCareMain.xaml.cs without violating MVVM architecture.
Or is there an alternative way of doing this.
I have used separate viewModels for user controls and the main window since they have their own responsibilities to perform.
I really hope you could help me with this.
You should either bind to the same view model from both UserControls, or use an event aggregator or messenger to send an event or a message from one component to another in a loosely coupled way as explained in this blog post.
If you don't use a framework, you'll have to implement the event aggregator yourself.

How to find dropped source in wpf

I have many ListView which contains items, some have content and some do not. I want to show filled box on the position of empty box. How to find out Id of filled box when we drag and how to find Dropbox position and detail of empty box and Listview? Listview Item showing as tile. And also describe types of event.
See Image
<DataTemplate DataType="{x:Type local:FieldSchedule}">
<StackPanel Background="{StaticResource EquipmentItemBackground}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" BorderBrush="Black" BorderThickness="1,1,1,0" CornerRadius="5,5,0,0" Width="243" Height="35"
VerticalAlignment="Center" HorizontalAlignment="Center" Padding="1" Background="#CFE2FC">
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<!--<ColumnDefinition Width="*"></ColumnDefinition>-->
</Grid.ColumnDefinitions>
<!--<TextBlock Grid.Row="0" Grid.Column="0" Text="Ticket #" Foreground="Black" FontSize="10"
VerticalAlignment="Center" HorizontalAlignment="Right"/>-->
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding OrderID}" Foreground="Black" FontSize="25"
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"/>
</Grid>
</StackPanel>
</Border>
<Border Grid.Row="1" Grid.Column="0" x:Name="Border" BorderBrush="Black" CornerRadius="0,0,5,5" BorderThickness="1,0,1,1" Width="243"
VerticalAlignment="Center" HorizontalAlignment="Center" Padding="1" Height="110" Background="White" AllowDrop="True" DragEnter="Border_DragEnter_1" DragLeave="Border_DragLeave_1" Drop="Border_Drop">
<StackPanel>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding ContactName}" Foreground="Black" FontSize="13" TextAlignment="Left"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,1,0,0" TextWrapping="NoWrap" FontWeight="Medium"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding JobName}" Foreground="Black" FontSize="13" TextAlignment="Left"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,1,0,0" TextWrapping="Wrap" FontWeight="Medium"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="{Binding City}" Foreground="Black" FontSize="13" TextAlignment="Left"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,1,0,0" TextWrapping="Wrap" FontWeight="Medium"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding EarlyIn}" Foreground="Black" FontSize="13" TextAlignment="Left"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,1,0,0" FontWeight="Medium"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding StreetAddress}" Foreground="Black" FontSize="13" TextAlignment="Left"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="57,1,0,0" TextWrapping="Wrap" FontWeight="Medium"/>
<Button Grid.Row="3" Grid.Column="0" x:Name="toggleButton1" Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Right" Width="24" Height="30" Padding="0" Background="White" BorderBrush="White" BorderThickness="0">
<Image Name="imgCalendar12" HorizontalAlignment="Right" Width="20" Height="30" Source="/Assets/cal.JPG" Margin="0"/>
<ie:Interaction.Triggers>
<ie:EventTrigger EventName="Click">
<ie:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadTileList},Path=DataContext.UnassingedCalendarPopUpComand}" CommandParameter="{Binding ElementName=toggleButton1}">
</ie:InvokeCommandAction>
</ie:EventTrigger>
</ie:Interaction.Triggers>
</Button>
</Grid>
</StackPanel>
</Border>
</Grid>
</StackPanel>
<!--<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadTileList}}}" Value="True" >
<Setter TargetName="Border" Property="Background" Value="{StaticResource EquipmentItemSelectedBackground}" />
</DataTrigger>
</DataTemplate.Triggers>-->
</DataTemplate>

Windows phone 8.1 universal app Image touch behaviour

I have a grid with images and textblocks, this is the xaml:
<Grid x:Name="ContainerView" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.ColumnSpan="2" Grid.RowSpan="4">
<Image Source="ms-appx:/Images/background_azure.jpg" Stretch="Fill"/>
</Grid>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="Gridway Mobile Lab" HorizontalAlignment="Center" FontSize="25" ></TextBlock>
<Rectangle
Grid.Row="1" Grid.Column="0"
Tapped="ToSampling"
/>
<Image Grid.Row="1" Grid.Column="0"
Margin="40,20,40,50"
Source="ms-appx:/Images/prelievi.png"
Stretch="Fill"
Tapped="ToSampling"
/>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="10,10,10,10"
Text="Lista Prelievi"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
/>
<Rectangle
Grid.Row="1" Grid.Column="1"
Tapped="ToSetting"
Margin="10,10,10,10"/>
<Image Grid.Row="1" Grid.Column="1"
Margin="45,25,45,50"
Source="ms-appx:/Images/settings.png"
Stretch="Fill"
Tapped="ToSetting"
/>
<TextBlock Grid.Row="1" Grid.Column="1"
Margin="10,10,10,10"
Text="Impostazioni"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
/>
<Rectangle
Grid.Row="2" Grid.Column="0"
Tapped="ToSync"
Margin="10,10,10,10"/>
<Image Grid.Row="2" Grid.Column="0"
Margin="40,10,40,50"
Tapped="ToSync"
Source="ms-appx:/Images/sync.png"
Stretch="Fill"
/>
<TextBlock Grid.Row="2" Grid.Column="0"
Margin="10,10,10,10"
Text="Sincronizza"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
/>
<Rectangle
Grid.Row="2" Grid.Column="1"
Tapped="ToMessages"
Margin="10,10,10,10"/>
<Image Grid.Row="2" Grid.Column="1"
Margin="40,10,40,50"
Tapped="ToMessages"
Source="ms-appx:/Images/message.png"
Stretch="Fill"
/>
<TextBlock Grid.Row="2" Grid.Column="1"
Margin="10,10,10,10"
Text="Avvisi"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
/>
<Rectangle
Grid.Row="3" Grid.ColumnSpan="2"
Tapped="ToTimbs"
Margin="10,10,10,10"/>
<Image Grid.Row="3" Grid.ColumnSpan="2"
Tapped="ToTimbs"
Margin="25,20,25,20"
Source="ms-appx:/Images/timbratura.png"
Stretch="Fill"
/>
<TextBlock
Grid.Row="3" Grid.ColumnSpan="2"
Margin="10,10,10,10"
Text="Timbrature"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
/>
</Grid>
My problem is simple, I want my images to have the same behaviour of a button when the user touches them. They simply have to "move back" and then come forward again exactly as the animation of touching a simple button.
It is ok even if only the image is moving like that, but I don't really know how to achieve this, any help will be really appreciate.
Thanks all and sorry for my bad english, if you need some more infos tell me

How do i add constraints phone 8.1 UAP Xaml

When I view my app in the Windows Phone 8.1 wvga 4 " the screen works fine as you see in the following screen shot
But when I view it on my 5"lumia it seems messaged up as in screenshot
I know the iPhone uses a constraints system to keep items in place on all resolutions is their something similiar in windows phone 8.1
<Page
x:Class="findaPhysio.findaPhysioSearchDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:findaPhysio"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:drawerLayout="using:DrawerLayout"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="RootLayout">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--Title bar -->
<Grid x:Name="TitleBar" Background="#373A36" Grid.Row ="0" Height="60">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Margin="5" x:Name="DrawerIcon" Grid.Column="0" Source="/Assets/ic_drawer.png" HorizontalAlignment="Left" Tapped="DrawerIcon_Tapped" />
<TextBlock Grid.Column="1" Text="findaPhysio" Foreground="White" VerticalAlignment="Center" FontSize="18"/>
</Grid>
<!--DrawerLayout bar -->
<drawerLayout:DrawerLayout Grid.Row="1" x:Name="DrawerLayout">
<!--MainPage -->
<Grid x:Name="MainFragment" Background="White">
<local:MapView x:Name="MyMap" Background="Black" Zoom="5" ShowTraffic="True" Margin="10,51,0,325" Loaded="MyMap_Loaded"/>
<TextBlock HorizontalAlignment="Left" Margin="18.167,281.833,0,0" FontSize="18" TextWrapping="Wrap" Text="Address" VerticalAlignment="Top" Width="85" Foreground="Black" Height="31" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<TextBlock.RenderTransform>
<CompositeTransform SkewX="4.332" TranslateX="1.174"/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="txtAddress" HorizontalAlignment="Left" FontSize="18" Margin="116,282,0,0" TextWrapping="Wrap" Text="Address" VerticalAlignment="Top" Width="175" Foreground="Black" RenderTransformOrigin="2.554,0.897"/>
<TextBlock HorizontalAlignment="Left" Margin="22,257,0,0" FontSize="18" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" RenderTransformOrigin="0,0.256" Foreground="Black" IsTextSelectionEnabled="True"/>
<TextBlock x:Name="txtTelephone" HorizontalAlignment="Left" FontSize="18" Margin="116,331,0,0" TextWrapping="Wrap" Text="Telephone" VerticalAlignment="Top" Foreground="Black" Tapped="txtTelephone_Tapped" Width="143"/>
<TextBlock HorizontalAlignment="Left" Margin="16,331,0,0" FontSize="18" TextWrapping="Wrap" Text="Telephone" VerticalAlignment="Top" Foreground="Black"/>
<TextBlock HorizontalAlignment="Left" Margin="16,325,0,0" FontSize="18" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Foreground="Black"/>
<Button x:Name="btnBookNow" Content="Book Now" HorizontalAlignment="Left" Margin="108,427,0,0" VerticalAlignment="Top" Foreground="#FF589E5B" Background="#FF71C975" Tapped="btnBookNow_Tapped"/>
<TextBlock HorizontalAlignment="Left" Margin="16,304,0,0" FontSize="18" TextWrapping="Wrap" Text="Town" VerticalAlignment="Top" Foreground="Black"/>
<TextBlock x:Name="txtName" HorizontalAlignment="Left" Margin="116,257,0,0" FontSize="18" TextWrapping="Wrap" Text="Name:" VerticalAlignment="Top" RenderTransformOrigin="0,0.256" Foreground="Black" IsTextSelectionEnabled="True"/>
<TextBlock x:Name="txtTown" HorizontalAlignment="Left" Margin="116,304,0,0" FontSize="18" TextWrapping="Wrap" Text="Town" VerticalAlignment="Top" Foreground="Black"/>
<TextBlock HorizontalAlignment="Left" Margin="16,358,0,0" FontSize="18" TextWrapping="Wrap" Text="Web" VerticalAlignment="Top" Foreground="Black"/>
<TextBlock x:Name="txtWeb" HorizontalAlignment="Left" FontSize="12" Margin="116,358,0,0" TextWrapping="Wrap" Text="Web" VerticalAlignment="Top" Foreground="Black" Tapped="txtTelephone_Tapped" Width="263" Height="22"/>
<TextBlock x:Name="lblsp" HorizontalAlignment="Left" Margin="16,385,0,0" FontSize="18" TextWrapping="Wrap" Text="Speciality" VerticalAlignment="Top" Foreground="Black"/>
<TextBlock x:Name="txttxtSpeciality" HorizontalAlignment="Left" FontSize="18" Margin="116,385,0,0" TextWrapping="Wrap" Text="Speciality" VerticalAlignment="Top" Foreground="Black" Tapped="txtTelephone_Tapped" Width="143"/>
</Grid>
<!--Favorites List Section -->
<Grid x:Name="ListFragment">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="#5490CC">
<TextBlock HorizontalAlignment="Center" Margin="0,5,0,5" Text="Physio Details"
FontSize="25"/>
</Border>
<ListView Grid.Row="1" VerticalAlignment="Center" x:Name="ListMenuItems">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Background="White" Margin="0,0,0,1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding}" Margin="10" VerticalAlignment="Center" FontSize="18" Foreground="Black" />
<Rectangle Grid.Row="1" HorizontalAlignment="Left" Fill="Gray" Width="500" Height="0.5"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</drawerLayout:DrawerLayout>
</Grid>
You should use GridColumns and GridRows property of Grid control for you XAML. You have problem with resolution, because you hardcode margins of you TextBlocks. You should write:
<Grid>
<Grid.RowDefinitions>
<RowDefition />
......
</Grid.RowDefinitions/>
<Grid.ColumnDefinitions>
....
</Grid.ColumnDefiniti‌​ons/>
.....
</Grid>
And after insert your TextBlock to need column and row, for ex.:
<TextBlock Grid.Row="1" Grid.Column="1" />

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll?

Hi guys i am facing an exception in the following code,this code was working fine but i dont understand what happened to it now:
Exception is :
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Provide value on 'System.Windows.StaticResourceExtension' threw an exception.
<UserControl x:Class="AFIC.View.WirelessConfigurationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:AFIC.Resources"
xmlns:view="clr-namespace:AFIC.View"
xmlns:viewmodel="clr-namespace:AFIC.ViewModel"
>
<UserControl.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Height" Value="30"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<ContentPresenter
x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="400" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" Margin="0,10">
<StackPanel Height="550" Orientation="Vertical" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="65"/>
<ColumnDefinition Width="205"/>
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.ColumnSpan="1"
HorizontalAlignment="Left"
Content="IP Configuration:"
Foreground="Black"
FontWeight="ExtraBold"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Content="Wireless IP Address"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Column="1"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP1,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP2,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="2"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP3,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="4"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP4,UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
<Label
Grid.Row="2"
Grid.ColumnSpan="1"
HorizontalAlignment="Left"
Content="AP Group Configuration"
Foreground="Black"
FontWeight="ExtraBold"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Content="Group ID"
Foreground="Black"
Opacity="0.8"
Margin="0,0,0,5"
/>
<TextBox
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Margin="0,0,0,5"
Text="{Binding GroupId,UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="3"
Grid.Column="2"
VerticalAlignment="Center"
Content="(1-1024)"
Foreground="Black"
Opacity="0.8"
Margin="0,0,0,5"
/>
<Label
Grid.Row="4"
Grid.Column="0"
VerticalAlignment="Center"
Content="AP Hardware Type"
Foreground="Black"
Opacity="0.8"
/>
<ComboBox
Grid.Row="4"
Grid.Column="1"
ItemsSource="{Binding AvailableHwTypes}"
SelectedItem="{Binding SelectedApHardwareType}"
>
</ComboBox>
<Button
Grid.Row="4"
Grid.Column="2"
Margin="10,0,0,0"
Command=""
Style="{StaticResource AddHwType}">
Add
</Button>
<Button
Grid.Row="6"
Grid.Column="3"
Margin="10,0,0,0"
Style="{StaticResource AppButtons}"
Command="{Binding ConfigWireless}">
Configuration
</Button>
<TextBox
Grid.Row="5"
Grid.ColumnSpan="3"
IsReadOnly="True"
IsEnabled="False"
Visibility="Hidden"
Height="10"/>
<DataGrid
Grid.Row="6"
Grid.ColumnSpan="3"
Height="100"
AutoGenerateColumns="False"
ItemsSource="{Binding wirelessconfiguration}"
SelectedValue="{Binding SelectedWireless}"
Name="dg"
>
<DataGrid.Columns>
<DataGridTextColumn Width="100" Header="S.No" Binding="{Binding Path=S_No}"/>
<DataGridTextColumn Width="100" Header="Group ID" Binding="{Binding Path=_groupId}"/>
<DataGridTextColumn Width="200" Header="AP Hardware Type" Binding="{Binding Path=_apHardwareType}"/>
</DataGrid.Columns>
</DataGrid>
<Label
Grid.Row="7"
Grid.Column="0"
HorizontalAlignment="Left"
Content="Network Configuration"
FontWeight="ExtraBold"
Foreground="Black"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="8"
Grid.Column="0"
VerticalAlignment="Center"
Content="SSID"
Foreground="Black"
Opacity="0.8"
/>
<TextBox
Grid.Row="8"
Grid.Column="1"
VerticalAlignment="Center"
Text="Guest Network"
/>
<Label
Grid.Row="9"
Grid.Column="0"
VerticalAlignment="Center"
Content="Security"
Foreground="Black"
Opacity="0.8"
/>
<ComboBox
Margin="0,5,0,8"
Grid.Row="9"
Grid.Column="1"
ItemsSource="{Binding ACAvailableSecurityTypes}"
SelectedItem="{Binding ACSelectedSecurityType}"
>
</ComboBox>
<view:ACSecurityStaticWEP
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACStaticWep, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypeWepIEEE
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWEPIEEE, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypeWPAUC
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWPAPersonal, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypEnterprise
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWPAEnterprise, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
Can anyone tell me where is the problem.Any help would be highly appreciable.
It seems that one of the StaticResources used does not exist:
Either:
AddHwType (Button Style)
AppButtons (Button Style)
BooleanToVisibilityConverter (Converter)
You might miss a merged dictionary somewhere or forgot to add a resource before using it. Review the XAML Resources page on MSDN for more info.
Solved:I was using wrong Static Resource i was writingStyle="{StaticResource AddHwType }" and it should be Style="{StaticResource AppButtons}" :)

Categories

Resources