標(biāo)簽屬性驶社,用于存放任何東西,所有控件都有Tag屬性
Tag可以用來存放存放圖層uri訪問地址等等
1
2
控件模板的數(shù)據(jù)獲取
XXX.Tag as YYY
舉例:
<Button Content="點(diǎn)擊我獲得Tag屬性的內(nèi)容" Height="100" Width="150" Tag="這是Tag的內(nèi)容" Click="ButtonBase_OnClick"></Button>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
//這里可以看出Tag是object测萎,可以存放任意數(shù)據(jù)類型
string tag = (sender as Button).Tag as string;
MessageBox.Show($"Tag的內(nèi)容是\"{tag}\"");
}
示例代碼
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Tag