I want to do a thing, in the selected row has a text box is my custom to go up, not found out from a database, I want to have selected these two data ID added to the database, at the same time, the value of the corresponding text box together add a table to the other, is each text box corresponding value, you have what way, it is best to have a code, I am a rookie, don't know theory out
Xaml code:
CodePudding user response:
1. Use ObservableCollection2. The Mode=TwoWay, so we can get to the front of the modified data,
Examples are as follows:
XAML:
CS background:
Public partial class MainWindow: Window
{
MainWindowViewModel vm=new MainWindowViewModel ();
Public MainWindow ()
{
InitializeComponent ();
Enclosing DataContext=vm;
}
Private void BtnTest_Click (object sender, RoutedEventArgs e)
{
Foreach (var item in the vm. The DataList)
{
//get data
}
}
}
Public class MainWindowViewModel
{
Public ObservableCollection
Public MainWindowViewModel ()
{
The DataList=new ObservableCollection
DataList. Add (new CTestInfo {an IsSelected=true, TestCaseInfo="option 1", ResShare=25.7});
DataList. Add (new CTestInfo {an IsSelected=false, TestCaseInfo="option 2", ResShare=36.9});
}
}
Public class CTestInfo
{
Public bool an IsSelected {get; The set; }
Public string TestCaseInfo {get; The set; }
Public double ResShare {get; The set; }
}
CodePudding user response:
The text box is a custom I, is to write their own data, not found out from a database, so, this does not applyCodePudding user response:
Do you know about the WPF data binding can be single, can also be a two-way street; Not to say that only found out from a database can be binding, in fact, in most cases the ViewModel is not found out directly from the databaseCodePudding user response:
Use your code, no, there is a better way?CodePudding user response: