0

我有 DataGrid 喜欢:

<DataGrid Name="paragonyDG" AutoGenerateColumns="False" CanUserAddRows="False" ItemsSource="{Binding zaznaczone}" >
                <DataGrid.Columns>
                    **<DataGridCheckBoxColumn Header="Zaznacz" Binding="{Binding check}"></DataGridCheckBoxColumn>**
                    <DataGridTextColumn Header="Nazwa paragonu" Binding="{Binding nazwa}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Wystawiony przez" Binding="{Binding osoba}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Kwota paragonu" Binding="{Binding kwota}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Rabat" Binding="{Binding rabat}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Data otwarcia" Binding="{Binding dataO}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Data zamknięcia" Binding="{Binding dataZ}"></DataGridTextColumn>
                    <DataGridTextColumn Header="Formy płatności" Binding="{Binding formy}"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

并将其绑定到类中:

public class zaznaczone
{
    public bool check { get; set; }
    public int docID { get; set; }
    public string nazwa { get; set; }
    public string osoba { get; set; }
    public decimal kwota { get; set; }
    public decimal rabat { get; set; }
    public string dataO { get; set; }
    public string dataZ { get; set; }
    public string formy { get; set; }
}

现在,在 datagrid.selectionchanged 中,我想选中此复选框。我试图将 selectedItem.columns[0] 解析为复选框,但我无法将 datagridrow 解析为“zaznaczone”。我如何检查复选框?

4

1 回答 1

0

指定:SelectedItem的属性。之后,您可以修改.DataGridSelectedItem="{Binding zaznaczoneItem}"checkzaznaczoneItem

请注意,您DataContext应该实施INotifyPropertyChanged. 我建议你看看MVVMLight 框架

于 2013-02-27T11:19:11.400 回答