locked
How to use a custom User Control in an app page

    Question

  • Hi,

    I'm building my first app, which is a game that uses a grid with a flat map of the Earth. The Grid is heavily divided into multiple columns and rows, each of which has a "Location" object, represented by a custom User Control, which seemed to be the best option as the control is a grid that holds (and shows) armies.

    I can likely create and define the "Location" object but the problem is that I don't know how to use them in the xaml page where the Earth Grid is defined. The Columns and rows have been set, but How do you insert the User Control "Location" into them?

    The Location User Control is in a file called "Location.xaml" and has its xaml.h and xaml.cpp files included and the file I want to use it in is called "GamePlay.xaml". Should I simply embed most of the "User Control" template in a resource dictionary? Will I need to declare it in "App.xaml"?

    Attached should be an image of the Grid from the page, snipped from the designer view so the columns and Rows are visible. In these squares is where I want to put the "Location" as one would do a button.

    Thanks

    Wednesday, July 30, 2014 8:56 PM

Answers

  • Hi,

    You can implement and load your UserControl in a Windows Runtime Component written in C# in a C++ app. You cannot load a C# Class Library in a C++ app.

    http://msdn.microsoft.com/en-us/magazine/jj651570.aspx

    And there is a sample  demonstrates how to create and use XAML UserControl elements and create custom controls for your projects:

    http://code.msdn.microsoft.com/windowsapps/XAML-user-and-custom-a8a9505e

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    • Edited by Anne Jing Monday, August 4, 2014 2:15 AM edit
    • Marked as answer by Anne Jing Thursday, August 7, 2014 1:15 AM
    Monday, August 4, 2014 2:08 AM

All replies

  • Hi,

    Please refer to the links below:

    http://www.dotnetcurry.com/showarticle.aspx?ID=930

    http://eren.ws/2013/10/11/creating-and-using-custom-user-controls-in-windows-store-apps-boredom-challenge-day-7/

    http://www.c-sharpcorner.com/UploadFile/99bb20/user-control-in-windows-8-apps-using-C-Sharp/

    The links above define how to create a user control and how to use it in windows store app.

    Hope these can help you!

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, July 31, 2014 3:09 AM
  • I'm afraid that, so far, the second two solutions are not working. I'm using Visual C++, where as all the articles given use Visual C# (I don't know how much of a difference that makes), but I was wondering if the first article, where a Class library is used, might work. The class library template is not available under Visual C++ but it is under Visual C# and I'd like to know if a visual C# Class library can be used by a Visual C++ App.

    If not, is there a way to ensure that my IDE (Visual Studio 2013 Professional) can actually register my control for use in my xaml pages?

    Thanks

    Friday, August 1, 2014 1:15 AM
  • Hi,

    You can implement and load your UserControl in a Windows Runtime Component written in C# in a C++ app. You cannot load a C# Class Library in a C++ app.

    http://msdn.microsoft.com/en-us/magazine/jj651570.aspx

    And there is a sample  demonstrates how to create and use XAML UserControl elements and create custom controls for your projects:

    http://code.msdn.microsoft.com/windowsapps/XAML-user-and-custom-a8a9505e

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    • Edited by Anne Jing Monday, August 4, 2014 2:15 AM edit
    • Marked as answer by Anne Jing Thursday, August 7, 2014 1:15 AM
    Monday, August 4, 2014 2:08 AM