I would like to get the name of a selected ellpise.
This is my c# code: (code behind)
private StackPanel generateSensorObject(int tempvalue, int diameter, string moduletype, string modulename, string macaddress, string lastdate, string description)
{
StackPanel s1 = new StackPanel();
Viewbox v1 = new Viewbox();
Grid g1 = new Grid();
ToolTip tool1 = new ToolTip();
StackPanel st1 = new StackPanel();
TextBlock tool1t1 = new TextBlock();
TextBlock tool1t2 = new TextBlock();
TextBlock tool1t3 = new TextBlock();
TextBlock tool1t4 = new TextBlock();
Button b1 = new Button();
ContextMenu m1 = new ContextMenu();
MenuItem mi1 = new MenuItem();
Ellipse e1 = new Ellipse();
e1.Height = e1.Width = diameter;
tool1t1.Text = "MAC Addresse: " + macaddress;
tool1t2.Text = "Typ: " + moduletype;
tool1t3.Text = "letzter Wert eingetroffen: " + lastdate;
tool1t4.Text = "Beschreibung: " + description;
b1.Content = "Diagramm";
st1.Children.Add(tool1t1);
st1.Children.Add(tool1t2);
st1.Children.Add(tool1t3);
st1.Children.Add(tool1t4);
st1.Children.Add(b1);
tool1.Content = st1;
TextBlock t1 = new TextBlock();
TextBlock t2 = new TextBlock();
t1.Text = modulename;
t2.Text = tempvalue.ToString();
t2.ToolTip = tool1;
tool1.StaysOpen = true;
g1.Children.Add(e1);
s1.Children.Add(t1);
g1.Children.Add(t2);
t2.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
t2.VerticalAlignment = System.Windows.VerticalAlignment.Center;
s1.MouseRightButtonUp += ButtonDiagramm_Click;
v1.Child = g1;
s1.Children.Add(v1);
return s1;
}
This is my methode to generate the ellpises.
Now I am trying to get the name of a selected ellipse on the canvas with the ButtonDiagram methode. But I don't know how to do that.
Does anybody know the trick? Thanks!
You can access to the RoutedEventArgs.Source
property, if your mouse rights click on some ellipse, it should be passed in there:
void ButtonDiagramm_Click(object sender, MouseButtonEventArgs e){
var ellipse = e.Source as Ellipse;
if(ellipse != null){
//do everything with ellipse here, not just access its Name
}
}