Personal Understanding: As and is
Is is equivalent to "=" in the judgment.
if(e.OriginalSource is Button)
As is generally used to convert another object
e.OriginalSource as Button
To obtain relevant attributes or values.
e.OriginalSource as RadioButton).Name.ToUpper()
The emergence of As and is generally in a routing event. These two keywords need to be used to dynamically generate different UI controls with different types or attributes.
For example, generate a button through
for(int i = 0;i<10;i++){ Button btn = New Button(); btn.Name = i.ToString();
stackPanel1.Children.Add(btn);
}
for(int i = 0;i<10;i++){ RadioButton btn = New RadioButton();
btn.Name = i.ToString();
stackPanel1.Children.Add(btn);
}
Route listening
this.stackPanel.AddHandler(Button.ClickEvent, new RoutedEventHandler(Btn_Click));
Event Processing
private void Btn_Click(object obj, RoutedEventArgs e){ object Obj = e.OriginalSource;
if(Obj is Button)
{
MessageBox.Show((Obj as Button).Name.ToString());
}
if(Obj is RadioButton)
{
MessageBox.Show((Obj as RadioButton).Name.ToString());
}
}
Complex conversions require a layer-by-layer access
Tabcontrol switching requirements
(Sender as tabcontrol). selecteditem as tabitem). header. tostring ();
DataGrid data operation requirements
(Sender as DataGrid). selecteditem as datarowview). Row ["c_id"]. tostring ();