SlideShare a Scribd company logo
Windows Application Development with Microsoft .NET Framework 4
Configuring Data Binding
1. Binding to Data Sources (brief overview of the previous lecture)
2. Manipulating and Displaying Data
by Oleksiy Korotchyn
Binding an Item Control to a List
<ListBox
ItemsSource="{Binding Source={StaticResource myCollection}}"
DisplayMemberPath="FirstName"
/>
myCollection can be:
2
 Simple array
 Collection
 ADO.NET Object
 ObjectDataProvider
 XmlDataProvider
Binding a Single Property to a List
 To show Items Collection (ToString())
<Label Content="{Binding }"/>
 To show Current item:
<Label Content="{Binding /}"/>
3
Binding to Hierarchical Data
 For ADO.NET object:
<Label Content="{Binding
Path=ProductTypes/TypesCategoriesRelation/CategoryName.Length}" />
<!– Table /Relation /Row .Property -->
 For array of objects:
<Label Content="{Binding /PropertyObject.PropertyObject.MyProperty}"/>
<Label Content="{Binding Path=PropertyObject.PropertyObject.MyProperty}"/>
4
Navigating a Collection or List
To get a reference to ICollectionView:
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
5
Binding to an Object with ObjectDataProvider
1) IsAsynchronous – indicates whether object creation and method calls are performed on the foreground thread
or on a background thread.
2) ObjectInstance – gets or sets the object used as the binding source.
 Let’s see example
6
Windows Application Development with Microsoft .NET Framework 4
Configuring Data Binding
1. Binding to Data Sources
2. Manipulating and Displaying Data
by Oleksiy Korotchyn
Data Templates
<DataTemplate>
<StackPanel>
<TextBlock>Company Name:</TextBlock>
<TextBlock Text="{Binding CompanyName}" />
<Label Content="{Binding Path=ContactName}"/>
</StackPanel>
</DataTemplate>
8
Data Templates
Setting the Data Template
<Label>
<Label.ContentTemplate>
<DataTemplate>
<!--Actual data template omitted-->
</DataTemplate>
</Label.ContentTemplate>
</Label>
9
Setting the Data Template
 Note that for item controls, the DisplayMemberPath and ItemTemplate properties are mutually exclusive.
(you can set one but not the other)
10
Using Converters to Apply Conditional Formatting in Data Templates
[ValueConversion(typeof(DateTime), typeof(Brush))]
public class DateBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo
culture)
{ … }
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
11
Using DataTemplateSelector
 The DataTemplateSelector class enables you to assign data templates dynamically to collection objects based on
the content of the data.
12
Using DataTemplateSelector
public class DateDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject
container)
{
FrameworkElement element = container as FrameworkElement;
if (element != null && item != null && item is System.Data.DataRowView)
{return element.FindResource("BasicTemplate") as DataTemplate; }
return null; }}
13
Using DataTemplateSelector
<Window x:Class="MainWindow"
…
<Window.Resources>
<my:DateDataTemplateSelector x:Key="myTemplateSelector" />
</Window.Resources>
<ListBox ItemTemplateSelector="{StaticResource myTemplateSelector}" />
</Window>
14
Using DataTemplateSelector
 Let’s see example
15
Using Hierarchical Data Templates
Item-Related Properties of HierarchicalDataTemplate:
1) ItemBindingGroup – gets or sets the BindingGroup property that is copied to each child item.
2) ItemContainerStyle – gets or sets the Style property that is applied to the item container for each child item.
3) ItemContainerStyleSelector – gets or sets custom style-selection logic for a style that can be applied to each item
container.
4) ItemsSource – gets or sets the binding for this data template, which indicates where to find the collection that
represents the next level in the data hierarchy
16
Using Hierarchical Data Templates
Item-Related Properties of HierarchicalDataTemplate:
5) ItemStringFormat – gets or sets a composite string that specifies how to format the items in the next level in the
data hierarchy if they are displayed as strings.
6) ItemTemplate – gets or sets the data template to apply to the ItemTemplate property on a generated
HeaderedItemsControl control (such as MenuItem or TreeViewItem) to indicate how to display items from the
next level in the data hierarchy.
7) ItemTemplateSelector – gets or sets DataTemplateSelector to apply to the ItemTemplateSelector property on a
generated HeaderedItemsControl control (such as MenuItem or TreeViewItem) to indicate how to select a
template to display items from the next level in the data hierarchy
17
Using Hierarchical Data Templates
 Let’s see example
18
Sorting Data
 Bound data can be sorted through the default ICollectionView element for the data list
19
Sorting Data
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("LastName",
System.ComponentModel.ListSortDirection.Ascending));
20
Sorting Data
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("LastName",
System.ComponentModel.ListSortDirection.Ascending));
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("FirstName",
System.ComponentModel.ListSortDirection.Ascending));
21
Applying Custom Sorting
public class MyComparer : System.Collections.IComparer
{
public int Compare(object x, object y)
{
Employee empX = (Employee)x;
Employee empY = (Employee)y;
return empX.LastName.Length.CompareTo(empY.LastName.Length);
}
}
22
Applying Custom Sorting
System.ComponentModel.ICollectionView myView;
myView =(ListCollectionView)CollectionViewSource.GetDefaultView(myCollection);
myView.CustomSort = new MyComparer();
23
Grouping
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
myView.GroupDescriptions.Add(new PropertyGroupDescription("EmployeeTitle"));
24
Grouping
Properties of GroupStyle:
 ContainerStyle – gets or sets the style applied to the GroupItem object generated for each item
 ContainerStyleSelector – represents an instance of StyleSelector that determines the appropriate style to use for
the container
 HeaderTemplate – gets or sets the template used to display the group header
 HeaderTemplateSelector – represents an instance of StyleSelector that determines the appropriate style to use
for the header
 Panel – gets or sets a template that creates the panel used to layout the items
25
Creating Custom Grouping
 To create a custom group, you must create a class that implements the IValueConverter interface, which exposes
two methods: Convert and ConvertBack.
26
Creating Custom Grouping
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
myView.GroupDescriptions.Add(new PropertyGroupDescription("Region", new
RegionGrouper()));
27
Filtering Data
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myItems);
myView.Filter = new Predicate<object>(myFilter);
28
Filtering Data
public bool myFilter(object param)
{
return (param.ToString().Length > 8);
}
29
Filtering ADO.NET Objects
The filter expression is a string expression in the following format:
<ColumnName> <Operator> <Value>
BindingListCollectionView myView;
myView = (BindingListCollectionView)CollectionViewSource.GetDefaultView(myItems);
myView.CustomFilter = "Sandwich = 'Muffaletta'";
30
Filtering, Grouping and Sorting
 Let’s see example
31
32
Questions?

More Related Content

What's hot

Interface connection
Interface connectionInterface connection
Interface connection
myrajendra
 
2310 b 09
2310 b 092310 b 09
2310 b 09
Krazy Koder
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
Shopping Cart Code
Shopping Cart CodeShopping Cart Code
Shopping Cart Code
hanaan wacan
 
Advance Webpage Devlopment .NET
Advance Webpage Devlopment .NETAdvance Webpage Devlopment .NET
Advance Webpage Devlopment .NET
PandeyABHISHEK1
 
Cart Page Code
Cart Page CodeCart Page Code
Cart Page Code
hanaan wacan
 
Core Data Migration
Core Data MigrationCore Data Migration
Core Data Migration
Monica Kurup
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDB
harithakannan
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
Everywhere
 
Dev308
Dev308Dev308
Dev308
guest2130e
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1
Mahmoud Ouf
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
Quang Nguyễn Bá
 
Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPF
Quang Nguyễn Bá
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPF
Quang Nguyễn Bá
 
KMI System
KMI SystemKMI System
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentprovider
Krazy Koder
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
Sisir Ghosh
 
Flex3 data binding
Flex3 data bindingFlex3 data binding
Flex3 data binding
guestdf3003
 
ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
Hock Leng PUAH
 
Android content providers
Android content providersAndroid content providers
Android content providers
Kurt Mbanje
 

What's hot (20)

Interface connection
Interface connectionInterface connection
Interface connection
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Shopping Cart Code
Shopping Cart CodeShopping Cart Code
Shopping Cart Code
 
Advance Webpage Devlopment .NET
Advance Webpage Devlopment .NETAdvance Webpage Devlopment .NET
Advance Webpage Devlopment .NET
 
Cart Page Code
Cart Page CodeCart Page Code
Cart Page Code
 
Core Data Migration
Core Data MigrationCore Data Migration
Core Data Migration
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDB
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
Dev308
Dev308Dev308
Dev308
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
 
Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPF
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPF
 
KMI System
KMI SystemKMI System
KMI System
 
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentprovider
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
Flex3 data binding
Flex3 data bindingFlex3 data binding
Flex3 data binding
 
ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Android content providers
Android content providersAndroid content providers
Android content providers
 

Similar to Configuring Data Binding part2 ABTO Software Lecture Korotchyn

Disconnected data
Disconnected dataDisconnected data
Disconnected data
aspnet123
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data Binding
Doncho Minkov
 
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
honey725342
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
jamessakila
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
Madhuri Kavade
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Farzad Wadia
 
Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)
Gilbok Lee
 
Ado.net
Ado.netAdo.net
Ado.net
Iblesoft
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
Abhishek Sur
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
sonia merchant
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.net
Sireesh K
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
Abhishek Sur
 
Knockout js
Knockout jsKnockout js
Knockout js
LearningTech
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
Paneliya Prince
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
Harman Bajwa
 
.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving
rloving10
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
Mahmoud Ouf
 
JAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and RetrievalJAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and Retrieval
Dr. Ranbijay Kumar
 

Similar to Configuring Data Binding part2 ABTO Software Lecture Korotchyn (20)

Disconnected data
Disconnected dataDisconnected data
Disconnected data
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data Binding
 
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)
 
Ado.net
Ado.netAdo.net
Ado.net
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.net
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
Knockout js
Knockout jsKnockout js
Knockout js
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
JAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and RetrievalJAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and Retrieval
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 

Configuring Data Binding part2 ABTO Software Lecture Korotchyn

  • 1. Windows Application Development with Microsoft .NET Framework 4 Configuring Data Binding 1. Binding to Data Sources (brief overview of the previous lecture) 2. Manipulating and Displaying Data by Oleksiy Korotchyn
  • 2. Binding an Item Control to a List <ListBox ItemsSource="{Binding Source={StaticResource myCollection}}" DisplayMemberPath="FirstName" /> myCollection can be: 2  Simple array  Collection  ADO.NET Object  ObjectDataProvider  XmlDataProvider
  • 3. Binding a Single Property to a List  To show Items Collection (ToString()) <Label Content="{Binding }"/>  To show Current item: <Label Content="{Binding /}"/> 3
  • 4. Binding to Hierarchical Data  For ADO.NET object: <Label Content="{Binding Path=ProductTypes/TypesCategoriesRelation/CategoryName.Length}" /> <!– Table /Relation /Row .Property -->  For array of objects: <Label Content="{Binding /PropertyObject.PropertyObject.MyProperty}"/> <Label Content="{Binding Path=PropertyObject.PropertyObject.MyProperty}"/> 4
  • 5. Navigating a Collection or List To get a reference to ICollectionView: System.ComponentModel.ICollectionView myView; myView = CollectionViewSource.GetDefaultView(myCollection); 5
  • 6. Binding to an Object with ObjectDataProvider 1) IsAsynchronous – indicates whether object creation and method calls are performed on the foreground thread or on a background thread. 2) ObjectInstance – gets or sets the object used as the binding source.  Let’s see example 6
  • 7. Windows Application Development with Microsoft .NET Framework 4 Configuring Data Binding 1. Binding to Data Sources 2. Manipulating and Displaying Data by Oleksiy Korotchyn
  • 8. Data Templates <DataTemplate> <StackPanel> <TextBlock>Company Name:</TextBlock> <TextBlock Text="{Binding CompanyName}" /> <Label Content="{Binding Path=ContactName}"/> </StackPanel> </DataTemplate> 8
  • 9. Data Templates Setting the Data Template <Label> <Label.ContentTemplate> <DataTemplate> <!--Actual data template omitted--> </DataTemplate> </Label.ContentTemplate> </Label> 9
  • 10. Setting the Data Template  Note that for item controls, the DisplayMemberPath and ItemTemplate properties are mutually exclusive. (you can set one but not the other) 10
  • 11. Using Converters to Apply Conditional Formatting in Data Templates [ValueConversion(typeof(DateTime), typeof(Brush))] public class DateBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { … } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } 11
  • 12. Using DataTemplateSelector  The DataTemplateSelector class enables you to assign data templates dynamically to collection objects based on the content of the data. 12
  • 13. Using DataTemplateSelector public class DateDataTemplateSelector : DataTemplateSelector { public override DataTemplate SelectTemplate(object item, DependencyObject container) { FrameworkElement element = container as FrameworkElement; if (element != null && item != null && item is System.Data.DataRowView) {return element.FindResource("BasicTemplate") as DataTemplate; } return null; }} 13
  • 14. Using DataTemplateSelector <Window x:Class="MainWindow" … <Window.Resources> <my:DateDataTemplateSelector x:Key="myTemplateSelector" /> </Window.Resources> <ListBox ItemTemplateSelector="{StaticResource myTemplateSelector}" /> </Window> 14
  • 16. Using Hierarchical Data Templates Item-Related Properties of HierarchicalDataTemplate: 1) ItemBindingGroup – gets or sets the BindingGroup property that is copied to each child item. 2) ItemContainerStyle – gets or sets the Style property that is applied to the item container for each child item. 3) ItemContainerStyleSelector – gets or sets custom style-selection logic for a style that can be applied to each item container. 4) ItemsSource – gets or sets the binding for this data template, which indicates where to find the collection that represents the next level in the data hierarchy 16
  • 17. Using Hierarchical Data Templates Item-Related Properties of HierarchicalDataTemplate: 5) ItemStringFormat – gets or sets a composite string that specifies how to format the items in the next level in the data hierarchy if they are displayed as strings. 6) ItemTemplate – gets or sets the data template to apply to the ItemTemplate property on a generated HeaderedItemsControl control (such as MenuItem or TreeViewItem) to indicate how to display items from the next level in the data hierarchy. 7) ItemTemplateSelector – gets or sets DataTemplateSelector to apply to the ItemTemplateSelector property on a generated HeaderedItemsControl control (such as MenuItem or TreeViewItem) to indicate how to select a template to display items from the next level in the data hierarchy 17
  • 18. Using Hierarchical Data Templates  Let’s see example 18
  • 19. Sorting Data  Bound data can be sorted through the default ICollectionView element for the data list 19
  • 20. Sorting Data System.ComponentModel.ICollectionView myView; myView = CollectionViewSource.GetDefaultView(myCollection); myView.SortDescriptions.Add(new System.ComponentModel.SortDescription("LastName", System.ComponentModel.ListSortDirection.Ascending)); 20
  • 22. Applying Custom Sorting public class MyComparer : System.Collections.IComparer { public int Compare(object x, object y) { Employee empX = (Employee)x; Employee empY = (Employee)y; return empX.LastName.Length.CompareTo(empY.LastName.Length); } } 22
  • 23. Applying Custom Sorting System.ComponentModel.ICollectionView myView; myView =(ListCollectionView)CollectionViewSource.GetDefaultView(myCollection); myView.CustomSort = new MyComparer(); 23
  • 24. Grouping System.ComponentModel.ICollectionView myView; myView = CollectionViewSource.GetDefaultView(myCollection); myView.GroupDescriptions.Add(new PropertyGroupDescription("EmployeeTitle")); 24
  • 25. Grouping Properties of GroupStyle:  ContainerStyle – gets or sets the style applied to the GroupItem object generated for each item  ContainerStyleSelector – represents an instance of StyleSelector that determines the appropriate style to use for the container  HeaderTemplate – gets or sets the template used to display the group header  HeaderTemplateSelector – represents an instance of StyleSelector that determines the appropriate style to use for the header  Panel – gets or sets a template that creates the panel used to layout the items 25
  • 26. Creating Custom Grouping  To create a custom group, you must create a class that implements the IValueConverter interface, which exposes two methods: Convert and ConvertBack. 26
  • 27. Creating Custom Grouping System.ComponentModel.ICollectionView myView; myView = CollectionViewSource.GetDefaultView(myCollection); myView.GroupDescriptions.Add(new PropertyGroupDescription("Region", new RegionGrouper())); 27
  • 28. Filtering Data System.ComponentModel.ICollectionView myView; myView = CollectionViewSource.GetDefaultView(myItems); myView.Filter = new Predicate<object>(myFilter); 28
  • 29. Filtering Data public bool myFilter(object param) { return (param.ToString().Length > 8); } 29
  • 30. Filtering ADO.NET Objects The filter expression is a string expression in the following format: <ColumnName> <Operator> <Value> BindingListCollectionView myView; myView = (BindingListCollectionView)CollectionViewSource.GetDefaultView(myItems); myView.CustomFilter = "Sandwich = 'Muffaletta'"; 30
  • 31. Filtering, Grouping and Sorting  Let’s see example 31