Git Product home page Git Product logo

winui3utilities's Introduction

WinUI3Utilities

Useful template methods for WinUI3 projects

Build

.NET Windows

Usage

The following is the general usage. For more details, see the XAML docs of the corresponding attributes.

Available APIs

Helpers

Helpers Usage
AppHelper Helper for Application
WindowHelper Get and set properties of Window
WindowSizeHelper Limit the size of the window (works with WindowSizeHelperAttribute)
DragMoveAndResizeHelper Apply drag-move and resize function to (UIElement)RootPanel
DragZoneHelper Reduce repetitive operations when using InputNonClientPointerSource
TitleBarHelper Set title bar
TeachingTipHelper Helper for TeachingTip
ContentDialogHelper Helper for ContentDialog
Misc Miscellaneous extension methods
ThrowHelper Throw helper

Attributes (Generators)

Attributes Usage
DependencyPropertyAttribute Generate a dependency property
LocalizedStringResourcesAttribute Generate for all the .resw and .resjson files in PRIResource under the specified namespace
SettingsViewModelAttribute* Generate property according to the properties of the settings class T for the specified viewmodel class
GenerateConstructorAttribute* Generate constructor like record for the specified type, according to the properties of it
AppContextAttribute* Generate field _containerConfiguration and methods Initialize/Load/SaveConfiguration for the specified class
WindowSizeHelperAttribute Generate helper properties to limit the window size (works with WindowSizeHelper)
AttributeIgnoreAttribute Ignores the effect of the specified attributes on this target
DisableSourceGeneratorAttribute Indicates that the source generator is disabled. This is usually used for debug purpose
  • Asterisk ("*") or boldness indicates that the attribute supports AttributeIgnoreAttribute

Settings Persistence

Only for packaged applications.

AppContext.cs:

using Windows.Storage;
using WinUI3Utilities.Attributes;

namespace Sample;

[AppContext<AppConfig>]
public static partial class AppContext
{
    public static string AppLocalFolder { get; private set; } = null!;

    public static void Initialize()
    {
        AppLocalFolder = ApplicationData.Current.LocalFolder.Path;
        InitializeConfiguration();
        AppConfig = LoadConfiguration() is not { } appConfigurations
            ? new() : appConfigurations;
    }

    public static void SetDefaultAppConfig() => AppConfig = new();

    public static AppConfig AppConfig { get; private set; } = null!;
}

AppConfig.cs:

using WinUI3Utilities.Attributes;

namespace Sample;

[GenerateConstructor]
public partial record AppConfig
{
    public int WindowWidth { get; set; } = 1280;
    public int WindowHeight { get; set; } = 720;
    ...
}

When saving configuration, you can use the following code:

AppContext.SaveConfiguration(AppContext.AppConfig)

Localization (Reference)

Generate for all the .resw and .resjson files in PRIResource under the specified namespace.

Sample.csproj

<Project Sdk="Microsoft.NET.Sdk">
    ... 
    <PropertyGroup>
        <EnableDefaultPriItems>false</EnableDefaultPriItems>
    </PropertyGroup>
    <Target Name="InjectAdditionalFiles" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun">
        <ItemGroup>
            <AdditionalFiles Include="@(PRIResource)" SourceItemGroup="PRIResource" />
        </ItemGroup>
    </Target>
    <ItemGroup>
        <CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="SourceItemGroup" />
    </ItemGroup>
    ...
    <ItemGroup>
        <PRIResource Include="**\*.resw" />
        <PRIResource Include="**\*.resjson" />
    </ItemGroup>
    ...
</Project>

AssemblyInfo.cs:

[assembly: LocalizedStringResources(nameof(Sample))]

XXX\APage.resw: ...

XXX\BWindow.resjson: ...

Project Link

NuGet GitHub

Contact Me

Poker

License

MIT License

winui3utilities's People

Contributors

dylech30th avatar poker-sang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

dylech30th

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.