标签属性,用于存放任何东西,所有控件都有Tag属性
Tag可以用来存放存放图层uri访问地址等等


控件模板的数据获取
XXX.Tag as YYY
举例:
<Button Content="点击我获得Tag属性的内容" Height="100" Width="150" Tag="这是Tag的内容" Click="ButtonBase_OnClick"></Button>
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
//这里可以看出Tag是object,可以存放任意数据类型
string tag = (sender as Button).Tag as string;
MessageBox.Show($"Tag的内容是\"{tag}\"");
}
示例代码
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Tag