Welcome to MSDN Blogs Sign in | Join | Help

Updated PDC samples

Here are the updated samples on popular demand.
Posted by Namitag | 1 Comments

Attachment(s): samples.zip

Binding to properties on the Window

I just got a question from someone who wanted to bind to properties on his Window class in his code behind and assumed that by simply saying <Binding Path="MyProperty"/> the Binding will automatically refer to the Window class. It is important to note that by default the Binding bind to properties on the DataContext of that element and not to those of the Window file.

So the right way to bind to properties on the Window is

<Window x:Class="demo.Window1"
xmlns=http://schemas.microsoft.com/winfx/avalon/2005
xmlns:x=http://schemas.microsoft.com/winfx/xaml/2005
Title="demo"
x:Name="window">

   <Grid x:Name="myGrid">
      <TextBlock Text="{Binding ElementName=window, Path=SimpleProperty}"/>
   </Grid>

</Window>

or by setting the DataContext to the Window.

<Window x:Class="demo.Window1"
xmlns=http://schemas.microsoft.com/winfx/avalon/2005
xmlns:x=http://schemas.microsoft.com/winfx/xaml/2005
Title="demo"
x:Name="window">

   <Grid x:Name="myGrid" DataContext="{Binding ElementName=window}">
      <TextBlock Text="{Binding Path=SimpleProperty}"/>
   </Grid>

</Window>

Infact, ElementName property on Binding lets you refer to any element in the current namescope and bind to properties on it. Now let me explain namescope since i've introduced it. A NameScope defines a scope in which you can only have one element with a specific unique name, and from which you can Find any element via name uniquely. A Page is one such scope, a Template and a Style is another scope. So from within a Template you can only refer to elements in that Template, similarly from within a Page you can only refer to elements in that page.

- Namita

 


 

Posted by Namitag | 0 Comments

My PDC Presentation - slides and demos

As promised i'm posting my slides as well as demos from my talk PRS324 - Using Data in WPF applications.

You can access my presentation at   PRS324

My 1st demo built up to show  singular Binding, list binding, DataTemplate, CollectionView/MasterDetail and ValueConverters. This one is available at Technology foundation demo . Note that in addition to what i showed in my presentation, i have added Buttons to do MoveNext and MovePrevious on the page. Also i've added a MultiBinding and MultiValueConverter to bind the position of the Clock hand to show the relative amount of time left for the auction to end which required me to bind to both RemainingTime and StartTime.

My 2nd demo showed flexible Template selection and the power of DataTemplates, where you can put anything ranging from 2D, 3D, Media etc. This demo is at DataTemplatePower .

In this demo I also showed a Grouped View of my data which easily grouped the same ListBox, to have 2 levels of grouping, each group having its own Style where one group is grouped simply by the property Category while the second group uses logic based on the Bid count to determine the grouping. Note how this particluar view is also Sorted in the CollectionView - all declaratively! You can access this at GroupedView .

My 3rd demo showed flexible layout in the list controls and specifically used TreeMap Panel to layout the children of the ItemsControl. In addition it showed how easy it is to support hierarchical data in WPF, by having an ItemsControl inside the DataTemplate for another ItemsControl. Also this particular sample is bound to ADO.NET DataTable. This demo is at TreeMap ADO demo

My 4rth demo showed databinding to xml into a TreeView using HiearchicalDataTemplates. This sample is at TreeView Xml demo.

njoy!

 

 

Posted by Namitag | 3 Comments

Starting my Blog...

After working in Microsoft and Windows Presentation Foundation for 4 years, I finally decided that I need to start blogging about how much I've learnt in the past 4 years and what an awesome platform we have built.

I've worked on various technologies in the platform including Property engine, databinding, styling, templating, commanding and controls and cannot wait to ship this stuff and get feedback from the community on what we've built. 

For those of you who are going to PDC, don't forget to attend my talk PRS324 - Using Data in Windows Presentation Foundation. I will be posting my slides and demos here, and also other bits and pieces of cool insights into the platform that can help you do some really cool stuff!

 

Posted by Namitag | 0 Comments
 
Page view tracker