Create dll from Windows 8.1 / Windows Phone 8.1 app with views and database

I am creating a Windows Phone 8.1 application that is supposed to act as a library for other Windows Phone 8.1 applications. In my new applications, I can add a library project to the solution and thus it functions as a kind of external library and that does what I want to do.
However, I would like to know if there is any way to export my WP Library application, such as a DLL, that I could add as a link to my new applications. Is there any other way I could do this?

It's worth noting that my library app will have views and even a database, not just methods to process data from the main app.

+3


source to share


1 answer


Since it is Windows 8.1 / Windows Phone 8.1. You can take a look at Store Apps โ†’ Universal Apps โ†’ Class Library (Portable for Universal Apps).


enter image description here

Once compiled into dll, just add the reference to the specified DLL to the reference folder.

To use your library in C #, just enter the namespace you use to create the library.

using your_namespace_from_library;

      

To use your views and what is not from XAML, just enter your namespace in the XAML file as well

<Page xmlns:YOUR_AWESOME_TAG="using:your_namespace_from_library">

      

Then you can use your tags from the library by following these steps:

<YOUR_AWESOME_TAG:Your_View>

      

:)


To fix the payload issue, check the error message, it should look like this:

enter image description here

Look at this very closely. It tries to reference a directory that doesn't exist to get the correct files. The solution (the only thing I know) is to go into that directory and make it. In my case, this is "C: \ Users \ Duan \ Documents \ Visual Studio 2013 \ Projects \ Chubosaurus.Charts_Old2 \ Chubosaurus.Charts \ bin \ Debug \ Chubosaurus.Charts"

For some reason, he decided to create an additional directory in the Debug folder where the dll is compiled. So create this folder which is the name of the library. And this is the part you won't like. Copy all the content of the Debug folder to the directory you just created (mainly the Theme folder).

Run your program again, your problems will be solved. But unfortunately you have to do this every time you compile the dll project . That's why I said just add the library project as part of the solution until you're ready to package it in NuGet. Hope it helps.


Simple library (tutorial)

Suppose I want to create a portable library to build a graphical call to ChubCharts , I create a project and load it using the default portable library with a call to the file Class1.cs

The first thing I do is delete this file :)

Then I add the template control from Add -> Add New Item -> Templated Control

I call that ChubosaurusCharts it should look like this as soon as it is generated.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;

public sealed class ChubosaurusCharts : Control
{
    public ChubosaurusCharts()
    {
        this.DefaultStyleKey = typeof(ChubosaurusCharts);
    }
}

      

Now I have the easiest control. Let's apply a ContentTemplate to it so I can make a Composite Control so it really needs to do something :)

Visual Studios makes a call to the Themes folder inside the solution. Inside this folder is a file called "Generic.xaml" that contains our template.

enter image description here

Now I want to edit the content that I will enter into my user control

Generic.xaml

<Style TargetType="local:ChubosaurusCharts">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:ChubosaurusCharts">
                <Border
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

      


By default it's just old <Border>

:(, I don't want that. As this is a diagram library. I would like to add a few things to the Visual Tree, basically <Canvas>

, so let's change that to:

<Style TargetType="local:ChubosaurusCharts">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:ChubosaurusCharts">
                <Canvas Background="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" DataContext="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}}">
                    <ContentPresenter Content="{Binding Surface}"></ContentPresenter>
                </Canvas>                    
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

      

You should now be guessing that you can add as many XAML tags as you like so that you render your control correctly. I just want to <Canvas>

.


Now with a little DataBinding magic, I bind the Canvas to my control's canvas for easy access :)

public sealed class ChubosaurusCharts : Control
{
    public ChubosaurusCharts()
    {
        this.DefaultStyleKey = typeof(ChubosaurusCharts);
        this.Surface = new Canvas();
    }

    private Canvas surface;

    public Canvas Surface
    {
        get
        {
            return surface;
        }
        set
        {
            surface = value;
        }
    }
}

      


It is now ready to use: D

Add the portable library to your solution added to the namespace. Compilation.

Omitting the crazy school school algebra and my RenderFunction (which just adds lines to the canvas)

Add our custom control to MainPage.xaml, you can also drag the control from the toolbar now: D

<chubo:ChubosaurusCharts x:Name="my_chart">

      

And the result of your hard work:

enter image description here

Cheers: D

+6


source







All Articles