开发者

How to trigger DataGridevents DataGridBeginningEdit, DataGridCellEditEnding with a Combobox in Silverlight? / CellTemplate for a Combobox

开发者 https://www.devze.com 2023-03-22 11:44 出处:网络
I want to use the DataGridevents (DataGridBeginningEdit, DataGridCellEditEnding, ..etc) to handle and detect changes. As far as I understood, without a \"CellTemplate\" these are not triggered. So I a

I want to use the DataGridevents (DataGridBeginningEdit, DataGridCellEditEnding, ..etc) to handle and detect changes. As far as I understood, without a "CellTemplate" these are not triggered. So I am trying to create an appropriate celltemplate using a TextBlock, but I guess it is not very straightforward with the binding I am using for the Combobox in the CellEditingTemplate, because I am using "DisplayMemberPath"..

There are examples of simpler cases but I couldn't find smth for this scenario. See Xaml snippet below;

<data:DataGridTemplateColumn Width="100">
                                    <data:DataGridTemplateColumn.CellTemplate>
                                        <Da开发者_JS百科taTemplate>
                                            <TextBlock HorizontalAlignment="Center" />
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellTemplate>
                                    <data:DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <ComboBox HorizontalAlignment="Stretch"
                                                        ItemsSource="{Binding DurationTypeList, Source={StaticResource itemSourceProvider}}"
                                                        SelectedValuePath="Code"
                                                        SelectedValue="{Binding Path=DurationTypeCode, Mode=TwoWay}" 
                                                        DisplayMemberPath="Template"  />
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellEditingTemplate>
                                </data:DataGridTemplateColumn>

Thank you


It turns out, i have two options..

Solution #1

<data:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock HorizontalAlignment="Left" Text="{Binding Path=DurationType.Template,  Mode=OneWay}"  />
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellTemplate>
                                    <data:DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <ComboBox HorizontalAlignment="Stretch"
                                                        ItemsSource="{Binding DurationTypeList, Source={StaticResource itemSourceProvider}}"
                                                        SelectedValuePath="Code"
                                                        SelectedValue="{Binding Path=DurationType, Mode=TwoWay}" 
                                                        DisplayMemberPath="Template"  />
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellEditingTemplate>

I changed the binding path from string to the object with Code and Template properties..

This blog helped a lot..

0

精彩评论

暂无评论...
验证码 换一张
取 消