Thursday, November 17, 2022

Infragistics ComboBoxField does not honor changes to AllowEdit

I just spent four hours trying to understand why a colleague was having a problem with an Infragistics ComboBoxField. The problem is insignificant, but it's not in the nature of my Asperger's personality to say "I don't know".

If you bind the AllowEdit property of a ComboBoxField, changes to that property are not reflected in the UI until you mouse over the control. 

Here's a short WPF C# .Framework project called ComboFieldBug that demonstrates the problem. It displays a XamDataGrid with two ComboBoxFields. The first has it's AllowEdit property bound and the second has its IsEnabled property bound.

Start by adding the required references.


The XAML looks like this.

<Window x:Class="ComboFieldBug.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        xmlns:local="clr-namespace:ComboFieldBug"
        mc:Ignorable="d"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <FrameworkElement x:Key="ProxyElement" DataContext="{Binding}"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <ContentControl Visibility="Collapsed" Content="{StaticResource ProxyElement}"/>
        <CheckBox IsChecked="{Binding IsComboEnabled}" Content="Enabled ComboBoxField"/>
        <igDP:XamDataGrid Grid.Row="1" DataSource="{Binding Items}">
            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>
                        <igDP:ComboBoxField ItemsSource="{Binding DataContext.Options, Source={StaticResource ProxyElement}}"
                                            Label="AllowEdit" Name="Option1" IsEditable="False"
                                            AllowEdit="{Binding DataContext.IsComboEnabled, Source={StaticResource ProxyElement}}"/>
                        <igDP:ComboBoxField ItemsSource="{Binding DataContext.Options, Source={StaticResource ProxyElement}}"
                                            Label="IsEnabled" Name="Option2" IsEditable="False"
                                            IsEnabled="{Binding DataContext.IsComboEnabled, Source={StaticResource ProxyElement}}"/>
                        </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>
    </Grid>
</Window>
 

and the code behind looks like this. There's nothing complicated here.

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
 
namespace ComboFieldBug
{
    public class cItem
    {
        public String Option1 { get; set; }
        public string Option2 { get; set; }
    }
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private ObservableCollection<cItem> _Items = new ObservableCollection<cItem>()
        {
            new cItem() {Option1 = "Alpha", Option2 = "Beta"},
            new cItem() {Option1 = "Beta", Option2 = "Gamma"}
        };
        public ObservableCollection<cItem> Items
        {
            get { return _Items; }
        }
 
        private ObservableCollection<String> _Options = new ObservableCollection<string> { "Alpha", "Beta", "Gamma" };
        public ObservableCollection<String> Options
        {
            get { return _Options; }
        }
 
        private bool _IsComboEnabled;
 
        public bool IsComboEnabled
        {
            get { return _IsComboEnabled; }
            set { SetProperty(ref _IsComboEnabled, value); }
        }
 
        public MainWindow()
        {
            InitializeComponent();
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
        public void SetProperty<T>(ref T storage, T value, [CallerMemberName] string name = "")
        {
            if (!Object.Equals(storage, value))
            {
                storage = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
 
    }
}
 
When you first run the application it looks like this. Both the AllowEdit and IsEnabled columns are disabled.



When you click the Enabled checkbox the IsEnabled field changes, but the AllowEdit field is unchanged. The user has no idea they can modify the AllowEdit field.




When you mouse over the AllowEdit field, the dropdowns become visible. They should have become visible when AllowEdit was set to true.



Curiously, setting DropDownButtonDisplayMode="Always" has no effect.

Update: Infragistics got back to me in a few hours and acknowledged this is a bug. They will keep me informed.

No comments:

Post a Comment