顯示具有 UWP 標籤的文章。 顯示所有文章
顯示具有 UWP 標籤的文章。 顯示所有文章

UWP Basic

註解:
Ctrl+K > Ctrl+U 註解
Ctrl+K > Ctrl+C 反註解

#Region 註解
#EndRegion

在Method上面打三個///
/// <summary>
/// Method introduce
/// <summary>

Log:
System.Diagonstics.Debug.WriteLine("");

Override:
protedted override > Select Method

專案內路徑:
ms-appx:///dir/file.txt

StringFormat:
string.Format("{0}{1}", value0, value1);

資料型態:
Dictionary<key, value>
List<value>

Background Color 為 SolidColorBrush / LinearGridentBrush
Margin / Border 為 Thickness
Grid.RowDefinitions / ColumnDefinitions 長寬單位為 GridLength
Visibility 含 Collapsed / Visible

UWP Navigate

透過 Navigate 可以進行換頁

- 第一個參數為換頁對象的 type

- 第二個參數為帶到下一頁的參數值 (型態為object可為任何類別, 在下一頁的 NavigateTo 時接收)


Page 類別可以複寫虛擬方法 OnNavigatedTo / OnNavigatedFrom :

* 進入順序為 建構子 -> OnNavigatedTo -> Page.Loaded

- OnNavigatedTo (當從其他頁面進入時)


- OnNavigatedFrom (從當前頁面離開時)



另外 回上一頁的方法為:


原生上一頁Button的ClickEvent:

UWP Font Width / Height

Create a TextBlock, call Measure method and pass in infinite size


And I can use the value to detect the number of line breaks in TextBlock

UWP Extension

1. 透過擴充方法 將靜態方法加入指定的類別

* 方法必須為 static

* this 後為指定擴充的類別

之後所有的 string 類別都可以使用這個擴展方法了


2. 透過 SetXXX / GetXXX 將靜態屬性加入指定的類別

* Set / Get方法都要有, 傳入與回傳的 element / value 類別都必須一致才會成立

* XXX 在 Xaml 中會成為屬性名稱

* 傳入的 element 類型為擴充對象 (下面例子為擴展 UserControl)

之後所有的 UserControl 都可以使用這個擴展屬性了

UWP PushNotification

Register a token from microsoft cloud service:



On Receive notification:

UWP Focus Next

1. 當Textbox 輸入Enter時  Focus下一個Control

2. 當Textbox 字數達MaxLength時 Focus下一個Control

UWP Attribute

C#可以透過 Attribute 標記 Class / Event / Struct...

- AttributeTargets 指定被標記對象的屬性

- Class 繼承自 Attribute

- Class 包含的變數為 Attribute 可設定的變數值



* 之後就可以在 AttributeTargets 所指定的 Variable 上加上 Attribute 標記



* 透過 TestClass 的 Type GetProperties 取得 TestClass 所有的變數屬性(event / class / struct...)

* 取得第 0 個變數的 GetCustomAttribute(typeof(DataBase))

* 如果 DataBaseAttribute != null 表示該變數上有 DataBase 的 CustomAttribute 標記




UWP SHA Encrypt

Encrypt:
Test:


* SHA is a digest algorithm, not an encryption algorithm. Digest values are not decryptable.

UWP AES Encrypt

AES Encrypt

* SecretKey String must be 32 char
* IV(Initialization vector) String must be 16 char


Block cipher mode:
* ECB (Electronic codebook,ECB)
* CBC (Cipher-block chaining)
* CFB (Cipher feedback)
* OFB (Output feedback)
* CTR (Counter)


UWP(C#) AES Encrypt:
UWP(C#) AES Decrypt:
Test: