January 2009 - Posts
I’m not an active twitterer, but I created an account several months ago. Just saw a pointer to thirteen23.com’s *chirp app, installed it.
It is such a nice app that it makes me want to twitter.
CNN’s themoment is a great example of how to capture an important moment!
The 3 scenes on the right are focused on Obama’s oath taking, the view from the mall, and the view from living rooms everywhere. Go full screen and walk around D.C. I like to navigate with my keyboard arrows, and then zoom in with mouse clicks…
An email inside Microsoft asked yesterday for the best way to determine if a XAML document is a “WPF” XAML document. This is my best answer:
.NET 4 Technique:
[requires .NET Framework 4’s System.Xaml.dll that we announced/demoed at PDC08]
This technique avoids creation of any objects specified in the XAML document and can tolerate x:Class or events in the XAML.
- bool isItWpf = IsWpfDocument("window1.xaml");
private static bool IsWpfDocument(string fileName)
{
Type rootType = GetXamlDocumentRootType(fileName);
bool isWpfSubclass = IsSubclassOfWpfType(rootType); //see this method in bottom section of post
return isWpfSubclass;
}
private static Type GetXamlDocumentRootType(string fileName)
{
XmlReader xmlReader = XmlReader.Create(fileName);
XamlXmlReader reader = new XamlXmlReader(xmlReader);
//Advance reader to the first (root) StartObject node (skips all namespace nodes)
while (reader.NodeType != XamlNodeType.StartObject)
{
reader.Read();
}
//Now grab its XamlType, and then the CLR Type.
XamlType rootXamlType = reader.Type;
Type rootType = rootXamlType.UnderlyingType;
return rootType;
}
.NET 3 Techniques:
Option A: Load the entire document via XamlReader.Load and then get the Type of the root object.
This technique does not avoid creation of any objects specified in the XAML document and cannot tolerate x:Class or events in the XAML.
- bool isItWpf = IsWpfDocumentRetro("window1.xaml");
private static bool IsWpfDocumentRetro(string fileName)
{
Type rootType = GetXamlDocumentRootRetro(fileName);
bool isWpfSubclass = IsSubclassOfWpfType(rootType); //see this method in bottom section of post
return isWpfSubclass;
}
private static Type GetXamlDocumentRootRetro(string fileName)
{
XmlReader xmlReader = XmlReader.Create(fileName);
//downside is that the entire document was processed (and the object graph was created.)
Type rootType = XamlReader.Load(xmlReader).GetType();
return rootType;
}
Option B: Use XmlReader and figure out the xmlns mapping to CLR namespace yourself.
This technique avoids creation of any objects specified in the XAML document and can tolerate x:Class or events in the XAML, but is kind of pain to write.
- Use XmlReader to find root element and namespace. Determine CLR Namespace based on parsing “clr-namespace:” uri, or walk all loaded assemblies for [assembly:XmlnsDefinition(…)] attributes to determine mapping from pretty xmlns to CLR-namespace. (we’ll keep this sample as an exercise for the reader).
Function used in both .NET 3 and .NET 4 Solutions
//This function will walk a types class hierarchy and return true if any of the types are from any
//of WPF's main 3 assemblies.
private static bool IsSubclassOfWpfType(Type type)
{
Assembly presentationFramework = typeof(FrameworkElement).Assembly;
Assembly presentationCore = typeof(UIElement).Assembly;
Assembly windowsBase = typeof(DependencyObject).Assembly;
Type baseType = type;
while (baseType != null)
{
Assembly assembly = baseType.Assembly;
if (assembly == presentationFramework
|| assembly == presentationCore
|| assembly == windowsBase)
{
return true;
}
baseType = baseType.BaseType;
}
return false;
}
Xceed has just updated their datagrid:
The new free Express Edition Xceed datagrid as well as the commercial Professional Edition, both at v3.1, have been released:
Even now that the WPF team now ships a DataGrid in the WPF Toolkit, many customers will still need/want features that are provided by DataGrids from component provider companies.
Update: updated the title to the proper spelling of Xceed. Sorry :-)
Our team has been doing great work since I last posted. WPF4 is shaping up nicely. I’m still mostly focused on System.Xaml and the XAML/BAML stack for WPF4.
Application Compatibility
We’ve been testing WPF4 (with its new XAML/BAML stack) with a number of applications. We’ll have very good application compatibility by our first Beta. As we are working through problems that we discover, sometimes it is a bug in our new stack, sometimes a missing few lines of code (IStyleConnector wasn’t being wired correctly up until last week), and sometimes it is totally crazy stuff that the v3 era parser did.
We are taking compatibility, even with pretty crazy things, very seriously. Our technique in System.Xaml.dll to enable compatibility is to provide a few properties on our different Settings objects that enable compatible behavior. Users of XamlReader.Load and Application.LoadComponent in WPF will automatically have those settings turned to the compatible way. Users of XamlServices.Load (in System.Xaml.dll) won’t have those settings set by default. We’ll see how that feels as we complete all the settings we have.
Anyway, recently we contacted Tim, Kevin, and Adam of InterKnowlogy for C-ME and Cristian Civera for Paperboy, since we needed some assistance to understand the XAML that the apps had as we get everything running happily.
How you can help when our beta ships
We won’t be able to test all apps out there, so some apps may have undiscovered issues with our first beta. When that ships (I’ll dig into our public date for that…), we’d really appreciate it if you could test your apps and help us understand any problems you find.
The size of our change is quite large, so beta testing is critical to help flush all issues out.