locked
How to get the RegisterName in WPF RRS feed

  • Question

  • I dynamic create the button using code like this:

    private void mainArea_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                    targetPoint = e.GetPosition((IInputElement)sender);
                    Uid id = new Uid();
                    string uid = id.getUid();
                    _target = new Button()
                    {

                        content = "station",

                        Name = "station" + uid

                    };
                    Canvas.SetTop(_target, targetPoint.Y - 60);
                    Canvas.SetLeft(_target, targetPoint.X - 20);
                    mainArea.Children.Add(_target);
                    mainArea.RegisterName(_target.Name, _target);
                }

    And the "uid" is a random number, after this code i can create button on Canvas, but when i try to delete it or do something else , i found i cant get the name of the button.

    so anyone can tell me how to get the name or registername of this button or the button that i click?

    Tuesday, October 13, 2020 2:11 AM

All replies

  • Hi rainnie1314,
    For questions about WPF, I suggest you ask the questions in Microsoft Q&A forum and you can get more professional answer.
    Thank you for your understanding.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 13, 2020 5:18 AM
  • thanks~~~
    Tuesday, October 13, 2020 5:39 AM