February 21, 2012

Asynchronous Programming with Async/Await

Easier Asynchronous Programming with the New Visual Studio Async

Every time an await is encountered, the currently executing method signs up the rest of the method as the thing to do when the current task is complete, and then immediately returns. Somehow each task will complete itself—either by being scheduled to run as an event on the current thread, or because it used an I/O completion thread or worker thread—and will then cause its continuation to “pick up where it left off” in executing the rest of the method.

Async Programming in Visual Studio 2010

The thing doing that work may be a background thread, an I/O completion thread, a graphic processing unit, or even the current thread. It doesn’t matter to the caller.

Await signifies two related things. First, it says that everything remaining in the method becomes the continuation for the method. A ‘continuation’ represents where the method will continue once the expression being awaited completes its work. Secondly, it tells the method to return.


Pause and Play with Await - How the Await and Async work underneath the covesr and how you can prepare for the m in .NET 4.0.

What is Binding?

Taken from the following article
What is "binding" and What makes it late? by Eric Lippert
Binding is the association of a syntactic element that names a method with a logical element of the program. So, speaking generally I would say that "binding" is any association of some fragment of syntax with some logical program element.

Basically by "early binding" we mean "the binding analysis is performed by the compiler and baked in to the generated program"; By "late binding" we mean "some aspect of the binding will be performed by the runtime" and therefore a binding failure will manifest as a runtime failure.

Early and late binding might better be called "static binding" and "dynamic binding"; static binding is binding performed using "static" facts known to the compiler, and dynamic binding is performed using facts "dynamically" known to the runtime.

February 17, 2012

WPF/Silverlight Data Binding

WPF Basic Data Binding FAQ - Better explanation than the one below.

WPF Data binding cheat sheet

Data Binding Overview - Basically, the target is the control and the source is the code property. Typically, each binding has these four components: a binding target object, a target property, a binding source, and a path to the value in the binding source to use. For example, if you want to bind the content of a TextBox to the Name property of an Employee object, your target object is the TextBox, the target property is the Text property, the value to use is Name, and the source object is the Employee object.

http://msdn.microsoft.com/en-gb/magazine/cc163299.aspx - Data Binding in WPF. Good introduction. Good short description of Xml data binding (though not 2 way I notice)

http://msdn.microsoft.com/en-us/magazine/cc700358.aspx - Customize Data Display with Data Binding and WPF. Some good stuff on hierarchical data templates and how to use them to fill a tree view using object data binding.

http://www.codeproject.com/Articles/26270/Understanding-WPF-via-ASP-NET - Nice article comparing WPF and ASP.NET data binding etc.

Also look at these related blogs
DisplayMemberpath
Data Templates

Bind "IsEnabled" of one control "cbXXX" to "IsChecked" property of another with name "cbYYY" in Xaml:
... Name="cbXXX" IsEnabled="{Binding ElementName=cbYYY, Path=IsChecked}" ...

February 16, 2012

DisplayMemberPath

DisplayMemberPath - Allows for simple binding on list type controls. Name or path on bound object that will be displayed for each item in the control.

See this article http://johnpapa.net/binding-to-silverlight-combobox-and-using-selectedvalue-selectedvaluepath-and-displaymemberpath - Nice ComboBox example that allows the user to chose some colors.

ObjectDataProvider

ObjectDataProvider - Wraps and creates an object that you can use as a binding source. Allows binding to objects that do not have a default constructor and that can be called Asynchronously.
http://www.thomasclaudiushuber.com/blog/2008/01/10/bind-to-methods-with-objectdataprovider/ - Nice simple example of using ObjectDataProvider

Data Templates

Taken from Top Ten UI Development Breakthroughs In Windows Presentation Foundation

You don't have to set the data template on a particular control. If you prefer, you can associate a data template with a particular type, indicating that WPF should use the specified template whenever it encounters that particular type as content.
eg
<Window.Resources> 
<DataTemplate DataType="{x:Type local:Person}"> <StackPanel Orientation="Horizontal"> <TextBlock FontWeight="Bold">Name:</TextBlock>
<TextBlock Text="{Binding Name}" Margin="2,0,10,0" /> <TextBlock FontWeight="Bold">
Date of birth:</TextBlock> <TextBlock Text="{Binding DateOfBirth}"Margin="2,0,10,0" /> </StackPanel> </DataTemplate> 
</Window.Resources>
Anything in the window that uses a Person object as its content will pick up this data template by default.

Example C++/CLI sealed properties and methods

This is to help remember the syntax of this stuff, it is too easy to forget
virtual void EnableStuff() sealed = IStuffEnabler::EnableStuff 
{
  stuffEnableImpl();  
}

virtual property bool IsStuffEnabled 
{
  bool get() sealed = IStuffEnabler::IsStuffEnabled::get
  {
 return stuffIsEnabledImpl();
  }
} 

Or split into source and header
Header file:
virtual void EnableStuff() sealed = IStuffEnabler::EnableStuff;
    
virtual property bool IsStuffEnabled 
{
  bool get() sealed = IStuffEnabler::IsStuffEnabled::get;
}      
and source file:
void StuffEnabler::EnableStuff() 
{
  stuffEnableImpl();  
}
    
bool StuffEnabler::IsStuffEnabled::get()  
{
    return stuffIsEnabledImpl();
}