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
585
How to set up binding for xamComboEditor in xamGrid?
posted

As check the sample on xamComboEditor in xamGrid, it is a little complicated:

<ig:TemplateColumn.EditorTemplate>
    <DataTemplate>
        <ig:XamComboEditor x:Name="CategoryEditList" Loaded="CategoryEditList_Loaded"
    ItemsSource="{StaticResource categoryProvider}"
    SelectedItem="{Binding Category,
    Mode=TwoWay,
    Converter={StaticResource categoryConverter},
    ConverterParameter={StaticResource categoryProvider}}"                 
    DisplayMemberPath="Value" />
    </DataTemplate>
</ig:TemplateColumn.EditorTemplate>
It uses converter with parameter and assume data source for itemSource from StaticeSource.

My case is like this:

Data coming from View Model:

For xamGrid ItemSource:

  private IList<Department> _myDepartments;
        public IList<MyDepartment> myDepartments
        {
            get { return _myDepartments; }
            set
            {
                if (this._myDepartments != value)
                {
                    this._myDepartments = value;
                    RaisePropertyChanged("myDepartments");
                }
            }
        }

  private IList<Department> _allDepartments;
        public IList<MyDepartment> AllDepartments
        {
            get { return _allDepartments; }
            set
            {
                if (this._allDepartments != value)
                {
                    this._allDepartments = value;
                    RaisePropertyChanged("AllDepartments");
                }
            }
        }

I want to xamComboEditor can be set in xaml like:

<ig:TemplateColumn.EditorTemplate>
<DataTemplate>   
<ig:XamComboEditor
    SelectedItem="{Binding Department, Mode=TwoWay}"  
    DisplayMemberPath="DeptName"
    ItemsSource="{Binding AllDepartments}" />
</DataTemplate>
</ig:TemplateColumn.EditorTemplate>

But it is obviously above binding not working.

How to implement with this situation?

 

Parents
No Data
Reply
  • 12631
    posted

    So basically you don't want to use the StaticResource on the combobox?

    Right now thats really the only way.  This is because the Column is not a DependencyObject (for performance reasons) so it does not inherit the DataContext.  The only way to get your data there is via StaticResource or setting it in code.

    Another option for you is to build your own custom column that abstracts all of the logic away into a column object:

    This blog post shows how to do that:  http://blogs.infragistics.com/blogs/devin_rader/archive/2010/07/08/creating-custom-columns-for-xamgrid.aspx

    Note the StaticResource still applies.

    In our 2011.1 release we're adding a native ComboBoxColumn to the grid for scenarios like this.  As with the solution mentioned thus far, the StaticResource restriction will still apply.

    Devin

     

Children
No Data