views:

133

answers:

0

Hello everybody, I was trying follow almost all tutorials regarding wpf data binding, I stil have problem to bind a comboBox with enum property which defined by me in a different namespace.

The enum:

namespace H3S.Interopability
{
    public enum eDataBits
    {
       DataBits5 = 5,
       DataBits6 = 6,
       DataBits7 = 7,
       DataBits8 = 8,
    }
}

Now I have some code with INotifyPropertyChanged:

namespace H3S.SerialSimulator
{
    public class SerialPortAdapter:INotifyPropertyChanged
    {
        //.......Some other code ........


        //And this
        public eDataBits DataBits
        {
            get
            {
                return (eDataBits)m_SerialPort.DataBits;
            }
            set
            {
                m_SerialPort.DataBits = (int)value;
                onPropertyChanged("DataBits");
            }
        }
    }
}

Now I"m trying to create A control and bind this field to comboBox

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:sys="clr-namespace:System;assembly=mscorlib"
 xmlns:interop="clr-namespace:H3S.Interopability;assembly=Interopability"
 xmlns:local="clr-namespace:H3S.SerialSimulator" 
 xmlns:ports="clr-namespace:System.IO.Ports;assembly=System"
 x:Class="H3S.SerialSimulator.SerialSimulationControl" Height="302.553333333333">
 <UserControl.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DataBitsEnum">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="interop:eDataBits" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Margin="0" RenderTransformOrigin="0.5,0.5">
    <ComboBox HorizontalAlignment="Left" Margin="66,28.625,0,0" VerticalAlignment="Top" Width="78.667" Height="17" Name="m_DataBits" ItemsSource="{Binding Source={StaticResource DataBitsEnum}}" SelectedValue="{Binding Path=DataBits}"/>
</Grid>

On runtime I have one line of code behind that set the dataContext of the layout.

This doesn't work, moreover, trying to replace the return value of DataBits property to system enum (Parity for example) will work excellent without any other change.

What I"m doing wrong, hell! :-)

Thanks for the help...