The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
First time development with Windows Template Studio (UWP) RRS feed

  • Question

  • Windows Template Studio (UWP) gives an easy start for developing a app with modern UI.

    It created two projects in my solution (example: MyApp) named, MyApp and MyApp.core. In the MyApp.core there's a readme.txt which recommends putting all the business logic in the core project for the entire solution. I'm new to the kind of project structure being used here and could not find clear directions on using it anywhere, although I do find info on individual components in general.

    For instance, there are the following directories in core project folder: Helpers, Models and Services.

    In the main project folder, these directories were created: Activation, Assets, BackgroundTasks, Helpers, Models, Services, Strings, Styles, TemplateSelectors and Views. 

    Now I have created a class which is basically a UDP listener. I want to instantiate it to listen to packets on different ports, parse it and call a callback function associated with that object of the class to process the parsed data, which can be as simple as displaying the messages in an XAML control. 

    My questions are:

    1. Where should I put this class?

    Whether inside the core project or the main project? In which folder?

    2. How can I reference it?

    I tried placing the class file in different locations, but I'm unable to reference the class. Do I need to add a separate reference for each class file I create?

    I have gone through Microsoft's documentation multiple times, but I'm not getting this part at all. So any helpful background, links are welcomed as well.


    Monday, November 11, 2019 11:20 PM

Answers

  • Hi,

    The project directory structure corresponds to the habit of writing code. You can judge the function of the file under this folder from the name of the folder, so that the file you want to create is placed in the corresponding directory.

    But this does not require you to do this, you can modify or add the folder, all of which can be done according to your own habits.

    >> 1. Where should I put this class?

    You created a UDP parsing class, you can choose to put it in the Helper folder, or create a Tools folder, specifically for placing similar tool classes.

    You may have questions about where to place. From your description, if this UDP parsing class focuses on the parsing of the package and returns the wrapped data, then it should be placed in the Core class library. Any classes not related to the UI should be placed in the Core.

    >> 2. How can I reference it?

    For example, I created the UDPHelper class in the Core/Helper directory. Now I want to use it in MainPage.xaml.cs.

    In the beginning we need to add a reference to the Core Library for our UWP project. You can find the Reference in the UWP project structure tree, right click, add a reference, find the Core class library in the project, and check it.

    But we don't need this step when creating a project using Windows Template Studio, because Visual Studio has already added references to us.

    We need to reference the UDPHelper namespace in the C# header.

    using TemplateStudio.Core.Helper

    Then we can use UDPHelper.

    Or you can use the full name of the namespace to use UDPHelper

    TemplateStudio.Core.Helper.UDPHelper helper = new TemplateStudio.Core.Helper.UDPHelper();

    Usually, with the code hints of Visual Studio, we only need to write UDPHelper, you will see a red wavy line and a light bulb, which is the code suggestion provided by Visual Studio, in which you can directly complete the steps of introducing the namespace, very Convenience.

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Tuesday, November 12, 2019 2:55 AM

All replies

  • Hi,

    Since this issue is related to UWP, this thread will be moved to UWP forum for better support.

    Best regards,

    Jeffrey


    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, November 12, 2019 2:20 AM
  • Hi,

    The project directory structure corresponds to the habit of writing code. You can judge the function of the file under this folder from the name of the folder, so that the file you want to create is placed in the corresponding directory.

    But this does not require you to do this, you can modify or add the folder, all of which can be done according to your own habits.

    >> 1. Where should I put this class?

    You created a UDP parsing class, you can choose to put it in the Helper folder, or create a Tools folder, specifically for placing similar tool classes.

    You may have questions about where to place. From your description, if this UDP parsing class focuses on the parsing of the package and returns the wrapped data, then it should be placed in the Core class library. Any classes not related to the UI should be placed in the Core.

    >> 2. How can I reference it?

    For example, I created the UDPHelper class in the Core/Helper directory. Now I want to use it in MainPage.xaml.cs.

    In the beginning we need to add a reference to the Core Library for our UWP project. You can find the Reference in the UWP project structure tree, right click, add a reference, find the Core class library in the project, and check it.

    But we don't need this step when creating a project using Windows Template Studio, because Visual Studio has already added references to us.

    We need to reference the UDPHelper namespace in the C# header.

    using TemplateStudio.Core.Helper

    Then we can use UDPHelper.

    Or you can use the full name of the namespace to use UDPHelper

    TemplateStudio.Core.Helper.UDPHelper helper = new TemplateStudio.Core.Helper.UDPHelper();

    Usually, with the code hints of Visual Studio, we only need to write UDPHelper, you will see a red wavy line and a light bulb, which is the code suggestion provided by Visual Studio, in which you can directly complete the steps of introducing the namespace, very Convenience.

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Tuesday, November 12, 2019 2:55 AM
  • That was really helpful, thank you.

    Thursday, November 14, 2019 4:32 PM