Friday, 30 July 2010

Binding to ListData (with IsSynchronizedWithCurrentItem)

Today while testing out data binding in WPF to list controls, I learnt something new.

On the window, I created two list boxes, and a textblock control all have data context of an xml static resource.

For the ItemsSource in listbox I was using: {Binding XPath=@name} [the xml resource contains a Color element with attribute 'name]. I used IsSynchronizedWithCurrentItem on both the listboxes and bound the TextBlock Text to {Binding XPath=@Name}.

On testing the app I found, the controls are not synchronized. After referring to MSDN and some testing with different bindings - I found that to enable synchronization between all the controls to the CurrentItem of the collection, it is important to bind the list boxes to the whole collection. and not to a member or attribute (in this example).

So for listboxes it should be ItemsSource={Binding}, for display purposes we can use DisplayMemberPath or DataTemplate.


Friday, 16 July 2010

SlickRun custom magic words

[msdn]
Filename="http://www.google.com/search?hl=en&q=$W$ site:msdn.microsoft.com"
Notes="Searches MSDN using Google"
GUID={2F9AC37E-9BD9-486D-9168-D7C2FF0D0750}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[msdngo]
Filename="http://www.google.com/search?hl=en&btnI=I%27m+Feeling+Lucky&q=$W$ site:msdn.microsoft.com"
Notes="Goes to the first Google search item on MSDN site"
GUID={E82C1293-A5C3-4D18-BBD7-BAFC543AC6EE}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[n]
Filename="notepad.exe"
Params="$W$"
GUID={B3DADC2D-B5EA-4186-B165-CDCF7F6BEF2F}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[stack]
Filename="http://stackoverflow.com/"
GUID={28BF5F9B-CAE3-48E9-A66E-440135239B96}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[times]
Filename="http://www.nytimes.com"
Notes="The New York Times"
GUID={6791C0B1-91B9-4946-BC16-07B58AEFF9DF}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[wi]
Filename="http://frer0342:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=$W$"
GUID={592A1690-DA02-4F3B-8C17-EDAF6A4FBF24}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[wikipedia,encyc]
Filename="http://en.wikipedia.org/wiki/Special:Search?search=$W$&go=Go"
Notes="Search Wikipedia Online Encyclopedia"
GUID={7A4FFA2F-1DC7-4580-B235-70A21AC1C586}
StartMode=5
UseRunAs=0
Disable32BitRedir=0
[word]
Filename="winword.exe"
Notes="Microsoft Word text editing tool"
GUID={C1F88DA3-A72C-4244-832D-340512AB6BC6}
StartMode=5
UseRunAs=0
Disable32BitRedir=0

Thursday, 15 July 2010

Dev Tools


- Slickrun: http://www.fiddlertool.com/SlickRun/

- Process explorer: http://technet.microsoft.com/fr-fr/sysinternals/bb896653.aspx



(Code snippet execution)


Wednesday, 7 July 2010

Using Attributes


I just realised that we have two ways to use an attribute.

For example the attribute - AttributeUsage - is implemented in the class AttributeUsageAttribute. And we can use either AttributeUsage or AttributeUsageAttribute in our code.

In fact if you create a custom attribute in class named "TestAttribute":

public class TestAttribute : Attribute
{
}

and define another custom attribute named "Test":

public class Test : Attribute
{
}

and then try using the attribute in a class:

[Test()]
public class MyClass
{ }

This will give compilation error:
'Test' is ambiguous between 'Test' and 'TestAttribute'; use either '@Test' or 'TestAttribute'

The code intellisense as well displays only the "Test" pointing to TestAttribute in its list, it doesn't show the other "Test".

I believe C# creates an alias of TestAttribute somewhere for the attribute. It actually makes sense to use aliased-name of attribute. It would be unwieldy to write attributes as WebMethodAttribute, ConditionalAttribute or AttributeUsageAttribute - just to name a few defined in the framework. Microsoft also uses the alias on MSDN.


Shorts - week 3, 2022

Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...