Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
365
xamComboEditor: strange behaviour when Value doesn't exist in ItemsSource.
posted

Hello forum:

When xamComboEditor.Value doesn't exist in its ItemsSource, its behaviour is as follows:

1) The value appears in the textBox part of the ComboEditor. 

2) When I click the button to open the dropwDown list, this value disappears.

3) If then I click in another control, the textBox part of the comboEditor shows its background in grey without any text. The text shown in 2) has disappeared.

I have a business class Employee whose property EmployeeCountryId has a value of "SPA".

 <local:Employee

   x:Key="MyEmployee"

   EmployeeId="1" EmployeeName="Penelope Cruz"

   EmployeeCountryId="SPA"

   /> 

 

The list of countries are:

<local:CountryCollection

   x:Key="MyCountryCollection">

   <local:CountryItem CountryId="GER" CountryName="Germany"/>

   <local:CountryItem CountryId="ITA" CountryName="Italy"/>

   <local:CountryItem CountryId="FRA" CountryName="France"/>

   <local:CountryItem CountryId="ENG" CountryName="England"/>

   <!--<local:CountryItem CountryId="SPA" CountryName="Spain"/>-->

   <local:CountryItem CountryId="POR" CountryName="Portugal"/>

</local:CountryCollection>

 

As you can see, the list doesn't contain SPA - Spain.

I use a dataTemplate for the country items:

 

 

 

<DataTemplate x:Key="CountryItemTemplate">

   <StackPanel  Orientation="Horizontal"  >

      <TextBlock Text="{Binding CountryId}" FontWeight="Bold" Width="25" />

      <TextBlock Text="{Binding CountryName}"/>

   </StackPanel>

</DataTemplate>

 

<Style x:Key="CountryComboStyle" TargetType="{x:Type ComboBox}">

   <Setter Property="ItemTemplate"

       Value="{StaticResource CountryItemTemplate}"/>

</Style>

If I bind the xamComboEditor itemSource to MyCountryCollection and the Value property of the XamComboEditor is bound to Employee.EmployeeCountryId, the result is that XamComboEditor shows the value ("SPA                ") without the CountryName because it does not exist in the dropdown list. So far so good.

<igEditors:XamComboEditor

   x:Name="CountryComboEditor"

   DataContext="{StaticResource MyCountryCollection}"

   Grid.Row="3" Grid.Column="1"

   ComboBoxStyle="{StaticResource CountryComboStyle}"

   Value="{Binding Source={StaticResource MyEmployee}, Path=EmployeeCountryId}"

   DisplayValueSource="Value"

   HorizontalAlignment="Left" Margin="3.5" VerticalAlignment="Stretch"

   Width="120" >

   <igEditors:XamComboEditor.ItemsProvider>

      <igEditors:ComboBoxItemsProvider              

         ItemsSource="{Binding Source={StaticResource MyCountryCollection}}"

         ValuePath="CountryId"

        />

   </igEditors:XamComboEditor.ItemsProvider>

</igEditors:XamComboEditor> 

But when I click the dropdown button, the text in the textbox part of. XamComboEditor is lost. It shows blanks in grey color.

How can I achive XamComboEditor  keeps the value although this doesn't exist in the dropdown list? When IsAlwaysInEditMode=True, the value isn't shown initially.

Thank you very much

I can suply a sample if needed.

Oscar