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
As Sheridan stated, you are attacking this problem from the wrong direction.
First of all - required reading if you haven't yet: Model-View-ViewModel Explained
You should create a set of Model objects that define your shapes, a set of ViewModel objects that expose them to the View and define their behavior, and a View which binds to the ViewModel.
A key difference in doing it this way is that now your logic for persisting to XML is not dependent on the UI at all, so you won't have to try to use something like Tag to pass around 'magic values'.
And, as an aside, I have found that the vast majority I've relied on using Tag for anything, that has been an indicator that I'm Doing It Wrong. :)
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,