Utilities for Universal Windows Platform
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Edi.UWP.Helpers

Helpers and Utils for Windows 10 UWP Projects. This document is not always keep updated with the library. Please check sample app also (also not always updated)

Download Sample App from Windows Store

Install

Install by NuGet:

PM> Install-Package Edi.UWP.Helpers

Features

Chinese Character Encoding

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri(ServiceEndpointUrl);
    var content = new FormUrlEncodedContent(new[] 
    {
        ...
    });
    var result = await client.PostAsync("", content);
    var resultContent = await result.Content.ReadAsByteArrayAsync();
    return DBCSEncoding.GetDBCSEncoding("gb2312").GetString(resultContent, 0,resultContent.Length - 1);
}

UI

Set App Window Launch Size
Edi.UWP.Helpers.UI.SetWindowLaunchSize(720, 360);
Set Color to App Title Bar
void ApplyColorToTitleBar()
{
    Edi.UWP.Helpers.UI.ApplyColorToTitleBar(
        Color.FromArgb(255, 0, 114, 188), 
        Colors.White, 
        Colors.LightGray, 
        Colors.Gray);

    Edi.UWP.Helpers.UI.ApplyColorToTitleButton(
        Color.FromArgb(255, 0, 114, 188), Colors.White, 
        Color.FromArgb(255, 51, 148, 208), Colors.White,
        Color.FromArgb(255, 0, 114, 188), Colors.White, 
        Colors.LightGray, Colors.Gray);
}

Value Converters

Recommend to add the coverters to App.xaml in order to use them across all Xaml pages in your application

<Application
    ...
    xmlns:converters="using:Edi.UWP.Helpers.Converters">
    <Application.Resources>
        ...
        <converters:DateTimeToOffsetConverter x:Key="DateTimeToOffsetConverter" />
        <converters:StringFormatConverter x:Key="StringFormatConverter" />
        <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        ...
    </Application.Resources>
</Application>
Usage

e.g. StringFormatConverters

<TextBlock Text="{Binding Date,Converter={StaticResource ResourceKey=StringFormat}, ConverterParameter='Last Update {0}'}" />

Other Converters:

  • BitmapImageConverter
  • BooleanToVisibilityConverter
  • ColorHexStringToBrushConverter
  • ColorHexStringToColorConverter
  • ColorToCMYKStringConverter
  • ColorToHexStringConverter
  • ColorToRgbStringConverter
  • ColorToSolidColorBrushValueConverter
  • DateTimeToOffsetConverter

Windows 10 Tasks

Redirect the user to Windows Store and open Review window for current App
private async void BtnReview_OnClick(object sender, RoutedEventArgs e)
{
    await Edi.UWP.Helpers.Tasks.OpenStoreReviewAsync();
}
Open Email Composing
private async Task ShowEmailCompse()
{
    await Tasks.OpenEmailComposeAsync(EmailTo, EmailSubject, EmailBody);
}

Selector Wrapper

  • Edi.UWP.Helpers.WrapperBase<T>

  • Edi.UWP.Helpers.SelectorWrapper<T> : WrapperBase<T>, INotifyPropertyChanged

Utility

Copy string to ClipBoard
Edi.UWP.Helpers.CopyToClipBoard("Hello");
Check if device is connected to the Internet
bool isConnected = Edi.UWP.Helpers.Utils.HasInternetConnection();
if (!isConnected)
{
    var dig = new MessageDialog("Please Check Internet Connection", "Are you TM kidding me?");
    await dig.ShowAsync();
    return;
}
Save InkCanvas strokes to .ink File
Load strokes from .ink file to InkCanvas
Convert ImageObject to Byte Array
Get Current App Version
public string Version => Edi.UWP.Helpers.Utils.GetAppVersion();
Get Current App Logo Image Uri
public Uri Logo => Edi.UWP.Helpers.Utils.GetAppLogoUri();
...
&lt;Image Source=&quot;{Binding Logo}&quot; Stretch=&quot;None&quot; /&gt;
Get Current App Display Name
public string DisplayName => Edi.UWP.Helpers.Utils.GetAppDisplayName();
Get Current App Publisher Name
public string Publisher => Edi.UWP.Helpers.Utils.GetAppPublisher();

Extension Methods

CollectionExtensions

ToObservableCollection

someIEnumerableObject.ToObservableCollection();