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
825
xamComboEditor LabelText when closed should be different than the DisplayText of an Item in the DropDown Menu
posted

Hello,

I create a xamDataPresenter as Grid with several Combobox Columns.
But the Label of the closed ComboEditior should show the text of a different Property than the DisplayText Property.
I tried to make a simple sample with a single xamComboEditor, but i didn't get it running as i want. (the sample is attached in this post)

What i did:
I created a Class for a ComboItem with three Properties (DisplayText, LabelText and Value).
I added a List of objects of that Class to the ItemsSource of a ComboBoxItemsProvider.
I set the ValuePath-Property to "Value" and the DisplayMemberPath-Property to "DisplayText".
Then i bind the Itemsprovider to the xamComboEditor. Everything works fine until that.
I tried to find a Property in the xamComboEditor to set the LabelText. The only property which made sence to me was the Text-PRoperty of the editor but this doesnt work because when you set this Property, the Editor tries to find a new fittable Item in its itemssource which leads to a exception.
I also tried this: this.xamComboEditor1.DisplayValueSource = DisplayValueSource.Value;
but it leads also to an exception.

Here's the code:

using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using Infragistics.Windows.Editors;
 
namespace WpfApplication1
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            List<DhpComboItem> itemList = new List<DhpComboItem>() {
                new DhpComboItem(1, "one"),
                new DhpComboItem(2, "two"),
                new DhpComboItem("drei""three"),
                new DhpComboItem(4, "four")
            };
 
            ComboBoxItemsProvider provider = new ComboBoxItemsProvider();
            provider.ItemsSource = itemList;
            provider.ValuePath = "Value";
            provider.DisplayMemberPath = "DisplayText";
 
            this.xamComboEditor1.ValueType = typeof(object);
            this.xamComboEditor1.ItemsProvider = provider;
            //this.xamComboEditor1.DisplayValueSource = DisplayValueSource.Value;
 
            this.xamComboEditor1.SelectedIndex = 0;
        }
 
        private void xamComboEditor1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            this.xamComboEditor1.Text = ((DhpComboItem)this.xamComboEditor1.SelectedItem).LabelText;
        }
    }
 
    public class DhpComboItem
    {
        public DhpComboItem(object value, string labelText)
        {
            Value = value;
            LabelText = labelText;
        }
 
        public object Value { getset; }
 
        public string LabelText { getset; }
 
        public string DisplayText
        {
            get
            {
                string displayText = string.Empty;
 
                if (Value != null)
                    displayText = Value.ToString() + "\t";
 
                return displayText + LabelText;
            }
        }
    }
}

Here's the xaml code:
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:igEditors="http://infragistics.com/Editors"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <igEditors:XamComboEditor HorizontalAlignment="Left" Margin="184,196,0,0" Name="xamComboEditor1" VerticalAlignment="Top" Width="228" SelectedItemChanged="xamComboEditor1_SelectedItemChanged" />
        <TextBox Text="{Binding ElementName=xamComboEditor1, Path=SelectedItem.Value}" Height="23" HorizontalAlignment="Left" Margin="184,236,0,0" Name="textBox1" VerticalAlignment="Top" Width="228" />
    </Grid>
</Window>

Thanks for your help,
Jochen

xamComboEditor_LabelText_Test.zip
Parents Reply Children
No Data