用户无法在 wpf 数据网格上添加空的新行
User can't add empty new row on wpf datagrid
在运行时,用户无法在我的 wpf 数据网格上添加新的空行。我试过 CanUserAddRow="True", IsReadOnly="False"
XAML
<DataGrid x:Name="UrunGrid" Grid.Row="0" CanUserAddRows="True" AlternatingRowBackground="LightGray" AlternationCount = "2" AutomationProperties.IsOffscreenBehavior="Offscreen">
<DataGrid.Columns>
<DataGridTextColumn Header="ISBN/Barkod" Binding="{Binding BARCODE}"/>
<DataGridTextColumn Header="Ürün Açıklaması" Binding="{Binding PRODUCT_NAME}"/>
<DataGridTextColumn Header="Adet" Binding="{Binding QUANTITY}"/>
<DataGridTextColumn Header="ISK" Binding="{Binding DISCOUNT}"/>
<DataGridTextColumn Header="KDV" Binding="{Binding TAX}"/>
<DataGridTextColumn Header="Birim Fiyat" Binding="{Binding PURCHASE_PRICE}"/>
<DataGridTextColumn Header="Tutar" Binding="{Binding AMOUNT}"/>
</DataGrid.Columns>
</DataGrid>
Class
class Invoice
{
public Int64 BARCODE { get; set; }
public string PRODUCT_NAME { get; set; }
public int QUANTITY{ get; set; }
public int DISCOUNT{ get; set; }
public int TAX{ get; set; }
public int PURCHASE_PRICE { get; set; }
public int AMOUNT { get; set; }
public static ObservableCollection<Invoice> getInvoice()
{
var invoice = new ObservableCollection<Invoice>();
return invoice;
}
}
XAML.CS
public partial class PurchaseInvoice : Page
{
private const Visibility visible = Visibility.Visible;
SqlDataReader dataReader;
public string cariadi { get; private set; }
public PurchaseInvoice()
{
InitializeComponent();
DataContext = Invoice.getInvoice();
}
}
我要;用户可以在此数据网格面板上创建新发票。每行代表一个产品。以及,用户如何使用箭头键控制数据网格?
感谢您的回复。
设置或绑定 DataGrid
的 ItemsSource
属性 到 ObservableCollection<T>
:
<DataGrid x:Name="UrunGrid" ItemsSource="{Binding}" ...
或者:
UrunGrid.ItemsSource = Invoice.getInvoice();
在运行时,用户无法在我的 wpf 数据网格上添加新的空行。我试过 CanUserAddRow="True", IsReadOnly="False"
XAML
<DataGrid x:Name="UrunGrid" Grid.Row="0" CanUserAddRows="True" AlternatingRowBackground="LightGray" AlternationCount = "2" AutomationProperties.IsOffscreenBehavior="Offscreen">
<DataGrid.Columns>
<DataGridTextColumn Header="ISBN/Barkod" Binding="{Binding BARCODE}"/>
<DataGridTextColumn Header="Ürün Açıklaması" Binding="{Binding PRODUCT_NAME}"/>
<DataGridTextColumn Header="Adet" Binding="{Binding QUANTITY}"/>
<DataGridTextColumn Header="ISK" Binding="{Binding DISCOUNT}"/>
<DataGridTextColumn Header="KDV" Binding="{Binding TAX}"/>
<DataGridTextColumn Header="Birim Fiyat" Binding="{Binding PURCHASE_PRICE}"/>
<DataGridTextColumn Header="Tutar" Binding="{Binding AMOUNT}"/>
</DataGrid.Columns>
</DataGrid>
Class
class Invoice
{
public Int64 BARCODE { get; set; }
public string PRODUCT_NAME { get; set; }
public int QUANTITY{ get; set; }
public int DISCOUNT{ get; set; }
public int TAX{ get; set; }
public int PURCHASE_PRICE { get; set; }
public int AMOUNT { get; set; }
public static ObservableCollection<Invoice> getInvoice()
{
var invoice = new ObservableCollection<Invoice>();
return invoice;
}
}
XAML.CS
public partial class PurchaseInvoice : Page
{
private const Visibility visible = Visibility.Visible;
SqlDataReader dataReader;
public string cariadi { get; private set; }
public PurchaseInvoice()
{
InitializeComponent();
DataContext = Invoice.getInvoice();
}
}
我要;用户可以在此数据网格面板上创建新发票。每行代表一个产品。以及,用户如何使用箭头键控制数据网格?
感谢您的回复。
设置或绑定 DataGrid
的 ItemsSource
属性 到 ObservableCollection<T>
:
<DataGrid x:Name="UrunGrid" ItemsSource="{Binding}" ...
或者:
UrunGrid.ItemsSource = Invoice.getInvoice();