Home > View Post

Xaml ObjectDataProvider. They really did think of everything

You may remember a previous post here on theJoyOfCode entitled DataTriggers. Does WPF have an answer for everything?. Well, recently I was working on a WPF application and needed to bind an enumeration (the System.Data.CommandType enum actually, you know: Text, StoredProcedure and TableDirect) to a combobox.

At first you may think you can just bind the actual type to the ItemsSource but, of course, a type is a type - not a collection. Wouldn't it be great if I could execute the Enum type's static GetValues() method which returns an array of the enum entries. Oh yes, that would work a treat.

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="commandTypeOptions">
                <x:Type TypeName="data:CommandType" />

    <ComboBox ItemsSource="{Binding Source={StaticResource commandTypeOptions}}" />


Of course this is basically the WinForms ObjectDataProvider that you're probably already familiar with. But to see it written out like this just hit me.

Tags: Xaml

Josh Post By Josh Twist
10:00 AM
11 May 2007

» Next Post: Accessing dlls in the GAC
« Previous Post: The Difference between GAT and GAX

Comments are closed for this post.

Posted by K venkata Kumar @ 17 Nov 2011 6:09 AM

<StackPanel Orientation="Vertical" >
<ObjectDataProvider ObjectType="{x:Type m:StringData}" x:Key="objStrings" MethodName="GetStrings"/>
<ListBox Name="lstStrings" Width="200" Height="300" ItemsSource="{Binding Source={StaticResource objStrings}}" />


the above xaml file it say "'m' is an undeclared namespace". Please give the solution

© 2005 - 2022 Josh Twist - All Rights Reserved.