Skip to content

Instantly share code, notes, and snippets.

View pabloportugues's full-sized avatar
🍊

José Martins pabloportugues

🍊
View GitHub Profile

Keybase proof

I hereby claim:

  • I am pabloportugues on github.
  • I am bytemybits (https://keybase.io/bytemybits) on keybase.
  • I have a public key ASDKhAxZxMe2A1J2v9sUi6fVhAN1pjDG5DQ6TH5UZOltFQo

To claim this, I am signing this object:

@pabloportugues
pabloportugues / MessengerExaples.cs
Last active November 25, 2015 14:52
Send and receive messages in a View and a ViewModel using MVVMLight
/* In a View */
// Register the Messenger
private void ControlLoaded(object sender, RoutedEventArgs e) {
Messenger.Default.Register<NotificationMessage>(this, NotificationReceived);
}
// Unregister the Messenger
private void ControlUnloaded(object sender, RoutedEventArgs e) {
Messenger.Default.Unregister<NotificationMessage>(this, NotificationReceived);
@pabloportugues
pabloportugues / CrossThreadUpdateUI.cs
Created November 24, 2015 15:08
How to allow the system to update the UI when the thread making the changes conflicts with the UI thread.
// For a ViewModel file
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => {
// Code goes here
});
// For a View file
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
// Code goes here
});
@pabloportugues
pabloportugues / LocalizationHelper.cs
Created November 6, 2015 15:17
Get Strings values from Resources.resw in code and XAML using the same key
using Windows.ApplicationModel.Resources;
namespace MyApp {
/// <summary>
/// Class responsible for retrieving values for a given key with regards for Localization
/// </summary>
public class LocalizationHelper {
private ResourceLoader _resourceLoader = null;
@pabloportugues
pabloportugues / ValidateUrlWithSyncToAsyncCall.cs
Created October 27, 2015 16:43
This is used to check for an url validity before navigating to it and halt navigation in the case validation fails or is false. To accomplish this we need to make a Synchronous call to an Asynchronous method so that the navigation holds, otherwise it will navigate before we have a validity result.
using System;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.Web.Http;
namespace TestApp.Utils {
/// <summary>
/// This is used to check for an url validity before navigating to it
/// and halt navigation in the case validation fails or is false
@pabloportugues
pabloportugues / MergeDictionariesTool.cs
Last active September 29, 2015 15:09
Merge two Resource Dictionaries in code
using System;
using System.Threading.Tasks;
namespace MyProject {
public class MergeDictionariesTool {
public MergeDictionariesTool() {
ResourceDictionary mainDictionary = new ResourceDictionary();
// Get the app main dictionary
mainDictionary.Source = new Uri("ms-appx", UriKind.RelativeOrAbsolute);