簡體   English   中英

WPF DataGridTemplateColumn 組合框更新所有行

[英]WPF DataGridTemplateColumn combobox updating all rows

我有這個 XAML,它從 ItemSource 是一個枚舉的組合框中選擇一個值。 我使用的教程是:

http://www.c-sharpcorner.com/uploadfile/dpatra/combobox-in-datagrid-in-wpf/

            <DataGrid x:Name="dgProductItem" 
                   ItemsSource="{Binding ProductVersion.ProductItems}"

            <DataGridTemplateColumn Header="Deployment Type" Width="120">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding DeploymentType}"></TextBlock>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <ComboBox ItemsSource="{Binding Source={StaticResource DeploymentTypeEnum}}"
                                  SelectedItem="{Binding DeploymentType}">

                        </ComboBox>
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>

但是,當我從一行更改值時,它將更新所有行 有人知道為什么是這樣嗎?

編輯:

如果我只更改一行,它只會更新該行,但是當我去更改另一行時,我剛剛更改的那一行也會更改前一行..

干杯

對重復的內容表示歉意,但經過幾個小時的猜測,因為網絡上沒有足夠的材料來處理這些內容,解決方案是:

</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <ComboBox ItemsSource="{Binding Source={StaticResource DeploymentTypeEnum}}"
                  SelectedItem="{Binding DeploymentType}"
                  **IsSynchronizedWithCurrentItem="false**">
        </ComboBox>
    </DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>

IsSynchronizedWithCurrentItem - 做它在罐頭上所說的。 但是,當您選擇一項時,當前項會消失,但至少不會更新所有行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM