locked
How to add classes RRS feed

  • Question

  • How do you add the class syntax from the library website, for example: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.appbarbutton.aspx
    Wednesday, June 17, 2015 12:19 PM

Answers

  • To handle the events in XAML, you simply add the handler's identifier in the event attribute. 

    <Control EventAttribute="EventHandler" />


    Make sure the signature of EventHandler is like this, 

    private void EventHandler(object sender, EventArgs e) {
       // Code...
       // Notice that e can have different types in 
       // different events.
    }

    This way you can handle the events. Otherwise, if you want to handle the events in back-end, just use a lambda expression, 

    myControl.SomeEvent += (sender, e) => 
    {
       // Code
    };

    Good thing about this method is that compiler would detect the types for sender and e on its own. You won't have to do much about it. 


    The sh*t I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem

    • Marked as answer by Kristin Xie Sunday, June 28, 2015 7:45 AM
    Wednesday, June 17, 2015 10:27 PM

All replies

  • Those are Windows XAML classes and work only in Windows Store projects. In those projects you don't have to add anything, the necessary libraries are already referenced.

    Wednesday, June 17, 2015 12:57 PM
  • So I only need to add the events? If so, how do I do this?
    Wednesday, June 17, 2015 10:20 PM
  • To handle the events in XAML, you simply add the handler's identifier in the event attribute. 

    <Control EventAttribute="EventHandler" />


    Make sure the signature of EventHandler is like this, 

    private void EventHandler(object sender, EventArgs e) {
       // Code...
       // Notice that e can have different types in 
       // different events.
    }

    This way you can handle the events. Otherwise, if you want to handle the events in back-end, just use a lambda expression, 

    myControl.SomeEvent += (sender, e) => 
    {
       // Code
    };

    Good thing about this method is that compiler would detect the types for sender and e on its own. You won't have to do much about it. 


    The sh*t I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem

    • Marked as answer by Kristin Xie Sunday, June 28, 2015 7:45 AM
    Wednesday, June 17, 2015 10:27 PM