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
70
Selected Item not getting reflected in XamComboeditor Silverlight
posted

Hello,

I am using silverlight XamComoEditor. In my scenario I need to bind string collection to the comboeditor. I have enabled editing. I got an exception when I entered a new item since the new String object was not getting created. I found a workaround for that.

My problem is when I select a value from the dropdown list, nothing gets selected i.e the selection is not retained. When I set the 'IsEditable' property to false, the item gets selected. But when I set it to True, the selection stops working. I guess I must be missing somthing.

Can anyone help me to make this work...

View is Like this: 

 

<

Grid x:Name="LayoutRoot" Background="White"><ig:XamComboEditor Height="30" Width="100" BorderBrush="Orange" ItemsSource="{Binding Path=StringCollection,Mode=TwoWay}" IsEditable="True" CustomValueEnteredAction="Add" DataObjectRequested="XamComboEditor_DataObjectRequested" VerticalAlignment="Top" Margin="0,70,0,0" /></Grid>

 

 

 

 Code Behind is like this:

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            ViewModel vm = new ViewModel();
            this.DataContext = vm;
        }

        private void XamComboEditor_DataObjectRequested(object sender, Infragistics.HandleableObjectGenerationEventArgs e)
        {

            List<UIElement> items = new List<UIElement>();

            GetChildren(((XamComboEditor)sender), typeof(TextBox), ref items);

            TextBox txtbox = (TextBox)items[0];           

            String str = new String(txtbox.Text.ToCharArray());

            e.NewObject = str;
            e.Handled = true;
        }

        private void GetChildren(UIElement parent, Type targetType, ref List<UIElement> children)
        {
            int count = VisualTreeHelper.GetChildrenCount(parent);
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
                    if (child.GetType() == targetType)
                    {
                        children.Add(child);
                        break;
                    }
                    GetChildren(child, targetType, ref children);
                }
            }
        }
    }

ViewModel is like this:

public class ViewModel
    {
        private ObservableCollection<string> stringCollection = new ObservableCollection<string>();

        public ObservableCollection<string> StringCollection
        {
            get { return stringCollection; }
            set { stringCollection = value; }
        }

        public ViewModel()
        {
            stringCollection.Add("test1");
            stringCollection.Add("test2");
            stringCollection.Add("test3");
            stringCollection.Add("test4");
            stringCollection.Add("test4");
            stringCollection.Add("test6");
        }

    }

 

 Thanks,

Shruti