WPF DataGrid自定义模板里面的数据怎么取 急!!!
通过 + - 对数量进行修改,不知道怎么取数量这个值,这个值是不绑定的
通过 + - 对数量进行修改,不知道怎么取数量这个值,这个值是不绑定的
绑定
XG是你自己创建类里面的成员变量
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:cs"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" >
</Grid>
namespace cs
{
///
/// MainWindow.xaml 的交互逻辑
///
public class Quantity
{
public string count { set; get; }
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
List<Quantity> Qu;
Quantity quantity;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Qu = new List<Quantity>();
quantity = new Quantity();
quantity.count = "0";
Qu.Add(quantity);
dataGrid.ItemsSource = Qu;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// List<Quantity> Qu1 = new List<Quantity>();
// Quantity quantity = new Quantity();
string data = Qu[dataGrid.SelectedIndex].count;
int indata = Convert.ToInt32(data);
indata = indata + 1;
quantity.count = Convert.ToString(indata);
dataGrid.ItemsSource = null;
Qu.Add(quantity);
dataGrid.ItemsSource = Qu;
}
}
}