Posts

Showing posts from January, 2020

How to show xml data in DataGrid?

XMLData.xml < Students >   < Student >     < Roll > 1 </ Roll >     < Name > Kumar </ Name >   </ Student >   < Student >     < Roll > 2 </ Roll >     < Name > Harsh </ Name >   </ Student > </ Students > Create a class for xml data public   partial   class   Student     {          public   int  Roll {  get ;  set ; }                          public   string  Name {  get ;  set ; }     } Code To get data from xml file XmlSerializer serializer =  new  XmlSerializer( typeof ( ObservableCollection<Student>) ,  new XmlRootAttribute( "Students" )); //here Student is type and Students is root of xml                        using  (StreamReader reader =  new StreamReader( @"D:\XMLData.xml" ))             {                 //Deserilize the xml file and assign to collection                 LstStudents =(ObservableCollectio

Validation By Exception (Display Error message by ToolTip) in Wpf using MVVM

View <Window x:Class="WpfPrismTutorial.Views.MainWindow"         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:local="clr-namespace:WpfPrismTutorial"         mc:Ignorable="d"         prism:ViewModelLocator.AutoWireViewModel="True"         xmlns:prism="http://prismlibrary.com/"         xmlns:valid="clr-namespace:WpfPrismTutorial.Validations"         Title="MainWindow" Height="450" Width="800">     <Grid VerticalAlignment="Center" HorizontalAlignment="Left">               <StackPanel Orientation="Horizontal">             <TextBlock Text="Val

Validation By ValidationRule in Wpf using MVVM

View <Window x:Class="WpfPrismTutorial.Views.MainWindow"         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:local="clr-namespace:WpfPrismTutorial"         mc:Ignorable="d"         prism:ViewModelLocator.AutoWireViewModel="True"         xmlns:prism="http://prismlibrary.com/"         xmlns:valid="clr-namespace:WpfPrismTutorial.Validations"         Title="MainWindow" Height="450" Width="800">     <Window.Resources>         <ControlTemplate x:Key=" errorTemplate ">             <StackPanel Orientation="Horizontal">             <AdornedElementPlaceholder x:N

Validation By IDataErrorInfo in Wpf using MVVM

<Window x:Class="WpfPrismTutorial.Views.MainWindow"         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:local="clr-namespace:WpfPrismTutorial"         mc:Ignorable="d"         prism:ViewModelLocator.AutoWireViewModel="True"         xmlns:prism="http://prismlibrary.com/"         xmlns:valid="clr-namespace:WpfPrismTutorial.Validations"         Title="MainWindow" Height="450" Width="800">     <Window.Resources>         <ControlTemplate x:Key=" errorTemplate ">             <StackPanel Orientation="Horizontal">             <AdornedElementPlaceholder x:Name

Validation By Annotation in Wpf using MVVM

View  <Window x:Class="WpfPrismTutorial.Views.MainWindow"         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:local="clr-namespace:WpfPrismTutorial"         mc:Ignorable="d"         prism:ViewModelLocator.AutoWireViewModel="True"         xmlns:prism="http://prismlibrary.com/"         xmlns:valid="clr-namespace:WpfPrismTutorial.Validations"         Title="MainWindow" Height="450" Width="800">     <Window.Resources>         <ControlTemplate x:Key=" errorTemplate ">             <StackPanel Orientation="Horizontal">             <AdornedElementPlaceholder x:

Validation By Exception in Wpf using MVVM

Image
View <Window x:Class="WpfPrismTutorial.Views.MainWindow"         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:local="clr-namespace:WpfPrismTutorial"         mc:Ignorable="d"         prism:ViewModelLocator.AutoWireViewModel="True"         xmlns:prism="http://prismlibrary.com/"         xmlns:valid="clr-namespace:WpfPrismTutorial.Validations"         Title="MainWindow" Height="450" Width="800">     <Window.Resources>         <ControlTemplate x:Key=" errorTemplate ">             <StackPanel Orientation="Horizontal">             <AdornedElementPlaceholder x:N

How to change background color of TabItems on mouse over?

<TabControl >             <TabControl.ItemContainerStyle>                 <Style TargetType="TabItem" BasedOn="{StaticResource {x:Type TabItem}}">                     <Setter Property="HeaderTemplate">                         <Setter.Value>                             <DataTemplate>                                 <StackPanel Orientation="Horizontal" Margin="5" >                                     <StackPanel.Style>                                         <Style TargetType="StackPanel">                                             <Setter Property="Background" Value="Red"/>                                             <Style.Triggers>                                                 <Trigger Property="IsMouseOver" Value="true">                                                     <Setter Property="