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
20
Binding ComboBoxColumn Itemssource to a alit in ViewModel with RelativeSource
posted

I want bind a list in my viewModel to itemssource of ComboBoxColumn but my code does not work.

but if i use a templatecolumn and in its edittemplate place a combobox, my syntax for itemssource worked

how can i solve my problem?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:wpfApplication28="clr-namespace:WpfApplication28"
x:Class="WpfApplication28.MainWindow"
Title="MainWindow" Height="350" Width="525">
           <Window.DataContext>
                <wpfApplication28:ViewModel />
           </Window.DataContext>
           <Grid>
                      <ig:XamGrid AutoGenerateColumns="False"
                        ItemsSource="{Binding Path=Products}">
                                <ig:XamGrid.EditingSettings>
                                           <ig:EditingSettings AllowEditing="Row"/>
                                 </ig:XamGrid.EditingSettings>
                                  <ig:XamGrid.Columns>
                                          <ig:TextColumn HeaderText="Name" Key="Name" Width="200" />
                                          <ig:ComboBoxColumn ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},
                                               Path=DataContext.Cities}" Key="City" DisplayMemberPath="Name"/>
                                   </ig:XamGrid.Columns>
                </ig:XamGrid>
             </Grid>
</Window>

Parents
  • 30945
    Offline posted

    Hello Mohammad,

     

    Thank you for you post. I have been looking into to question that you are having and the ComboBoxColumn is not deriving from the FrameworkElement class and is not part of the Visual Tree of the application, which means that when you are using binding to some of the properties of the Columns of the XamGrid, you should set the Source of the binding.

     

    I have created a sample application for you, that shows how you can create a Binding Proxy class that allows you to bind property of a Column in the Columns collection of the XamGrid to either the XamGrid itself or to its DataContext as follows:

     

                    <ig:ComboBoxColumn

                        Key="City"

                        DisplayMemberPath="Name">

                        <local:FieldBindingProxy.FieldBindingProxies>

                            <local:FieldBindingProxyCollection>

                                <local:FieldBindingProxy

                                    BindingSource="DataContext"

                                    PropertyPath="Cities"

                                    FieldPropertyPath="ItemsSource"/>

                            </local:FieldBindingProxyCollection>                            

                        </local:FieldBindingProxy.FieldBindingProxies>

                    </ig:ComboBoxColumn>

     

    This allows you to bind the ItemsSource of the ComboBoxColumn to the Cities property of the DataContext of the XamGrid.

     

    Please let me know if you need any further assistance on the matter.

     

    Sincerely,

    Krasimir, MCPD

    Developer Support Supervisor - XAML

    Infragistics

    www.infragistics.com/support

    ColumnBindingProxy.zip
Reply Children
No Data