T
T
Toxygen2016-04-18 18:22:29
WPF
Toxygen, 2016-04-18 18:22:29

How to add actions to event handlers of standard components?

I'm trying to implement my Control inherited from TreeViewItem

public class TreeViewItemExt : TreeViewItem
  {

  }

At the output, you need to get a control with additional logic for responding to standard events, for example, changing the selected element. How can I add this logic to the class definition?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Toxygen, 2016-04-18
@Toxygen

Figured out the issue:

public class TreeViewItemExt : TreeViewItem
  {
    public TreeViewItemExt()
      : base()
    {
      this.Selected += new RoutedEventHandler(msg); 
    }

    public void msg(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("TreeViewItemExt Works!");
    }
  }

Helped article https://wpffromscratch.wordpress.com/2015/03/20/ex...

S
Stanislav Makarov, 2016-04-18
@Nipheris

to change the selected element

If so, then you need a TreeView and OnSelectedItemChanged .

A
AxisPod, 2016-04-19
@AxisPod

Option 1: WPF has an EventTrigger that allows you to do whatever you want.
2nd use MVVM and interface INotifyPropertyChanged and binding
3rd option you have already been answered, use standard event SelectedItemChanged.
4th binding on SelectedItem, the selected element will come to the setter
PS Or rather 1 + 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question