最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Binding Datagird ComboboxColumn Event using xaml behaviors - Stack Overflow

programmeradmin3浏览0评论

I am trying to trigger an event when a ComboBoxColumn selection in a DataGrid changes. But I cannot get the binding to work. When I debug DataContext is shown as null. No matter what I try I can't seem to locate the DataContext. Oddly enough TestCommand is recognised by intellisence. xaml is as follows:

        <CollectionViewSource x:Key="GridViewSource" Source="{Binding vmCollection}"/>
        <CollectionViewSource x:Key="CurrenciesList" Source="{Binding Currencies}"/>



        <DataGrid x:Name="MyGrid"
                  ItemsSource="{Binding Source={StaticResource GridViewSource}}">

                <DataGridComboBoxColumn Header="Currency"
                                        ItemsSource="{Binding Source={StaticResource CurrenciesList}}"
                                        DisplayMemberPath="Name"
                                        SelectedValuePath="Code"
                                        SelectedValueBinding="{Binding CurrencyCode}">

                    <behaviors:Interaction.Triggers>
                        <behaviors:EventTrigger>
                            <behaviors:InvokeCommandAction EventName="SelectionChanged"
                                'Issue is here
                                Command="{Binding TestCommand}"/>
                        </behaviors:EventTrigger>
                    </behaviors:Interaction.Triggers>
                </DataGridComboBoxColumn>

        </DataGrid>

When I try the below on a button in the datagrid, everything works as expected. But not if I use them for the Combobox column event.


Command="{Binding DataContext.TestCommand,  RelativeSource={RelativeSource AncestorType=DataGrid}}" 
Command="{Binding DataContext.TestCommand,  ElementName=MyGrid}" 

发布评论

评论列表(0)

  1. 暂无评论