How to get tag of an element in c# wpf?

前端 未结 2 1031
一个人的身影
一个人的身影 2021-01-28 03:12

I am trying to build a GUI using WPF, in which I can draw some basic shapes and store them into a xml file. Shapes are designed in a xaml file, and I added tags for each of them

2条回答
  •  猫巷女王i
    2021-01-28 03:59

    Here is a example: assuming you have UI element is XAML (Button named _btn) with Tag property set to some value, then in any event handle (e.g. Click) associated with that element in code behind you can get the Tag value as follows:

    _btn.Click+=(s,e,)=>{ string _tag = (s as Button).Tag.ToString(); };
    

    You can apply the same logic to you case. Rgds,

提交回复
热议问题