Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding ComboBox to enum
Message
From
18/12/2012 10:24:51
 
 
To
18/12/2012 10:15:50
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01559922
Message ID:
01560018
Views:
48
>>>>I think the main problem is that the ObjectDataProvider must be in Windows.Resources. Something like this:
<Window x:Class="WpfApplication1.MainWindow"
>>>>        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>>>>        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>>>>        xmlns:local ="clr-namespace:WpfApplication1"
>>>>        xmlns:sys="clr-namespace:System;assembly=mscorlib"
>>>>        Title="MainWindow" Height="350" Width="525">
>>>><Window.Resources>
>>>>    <ObjectDataProvider x:Key="rates"
>>>>                    MethodName="GetValues" 
>>>>                    ObjectType="{x:Type sys:Enum}">
>>>>      <ObjectDataProvider.MethodParameters>
>>>>        <x:Type TypeName="local:RateType" />
>>>>      </ObjectDataProvider.MethodParameters>
>>>>    </ObjectDataProvider>
>>>>  </Window.Resources>
>>>><ComboBox ItemsSource="{Binding Source={StaticResource rates}}"></ComboBox>  
>>>></Window>
I just tried this with RateType defined in the same window so you'll need to adjust.
>>>>
>>>>UPDATE: Should have said " with RateType defined in the same namespace as the window"
>>>>
>>>>HTH,
>>>>Viv
>>>
>>>Thanks, one step forward :)
>>>
>>>I've adjusted the code like this:
>>>
>>>
    <Window.Resources>
>>>        <ObjectDataProvider x:Key="rateTypes"
>>>                    MethodName="GetValues" 
>>>                    ObjectType="{x:Type sys:Enum}">
>>>            <ObjectDataProvider.MethodParameters>
>>>                <x:Type TypeName="SamaanSystems_IBC_Business:RateType" />
>>>            </ObjectDataProvider.MethodParameters>
>>>        </ObjectDataProvider>
>>>    </Window.Resources>
>>>
>>>But I get an error: Type 'SamaanSystems_IBC_Business:RateType' was not found.
>>>
>>>I have this defined:
>>>
>>>
xmlns:SamaanSystems_IBC_Business="clr-namespace:SamaanSystems.IBC.Business;assembly=SamaanSystems.IBC.Business"
>>>
>>>and this defined:
>>>
>>>
namespace SamaanSystems.IBC.Business
>>>{
>>>	/// <summary>
>>>	/// Summary description for Rate.
>>>	/// </summary>
>>>	public partial class Rate
>>>	{
>>>         public enum RateType : int
>>>         {
>>>             Standard = 1,
>>>             Mail = 2,
>>>             ZipX = 3
>>>         }
>>>       }
>>>}
>>>
>>>Do you see what's causing this?
>>>
>>>Learning new stuff can be veeeeery frustrating at times :(
>>
>>I don't think you can nest RateType inside the partial class. Any reason why it has to be that way ?
>
>I guess not. I just thought as it "belonged" to my business object that was the place to put it. Where would you suggest?

You could just move it out of the class but keep it in the same namespace:
namespace SamaanSystems.IBC.Business
{
	public partial class Rate
	{
                }
               public enum RateType : int
               {
                    Standard = 1,
                    Mail = 2,
                    ZipX = 3
               }
}
Of course, if there's nothing else in Rate then the class is redundant.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform