Skip to content

Instantly share code, notes, and snippets.

@karno
Created December 22, 2014 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karno/6ce647221e790d692567 to your computer and use it in GitHub Desktop.
Save karno/6ce647221e790d692567 to your computer and use it in GitHub Desktop.
Skylight example C# code
using TestApp.Views;
using Skylight;
using Skylight.Common;
using Skylight.Messaging;
using Windows.ApplicationModel.Activation;
using Windows.Storage.Pickers;
using Windows.UI.Popups;
namespace TestApp.ViewModels
{
public class MainPageViewModel : ViewModel,
INavigationStateProvider,
IContinuable<FileOpenPickerContinuationEventArgs>,
IContinuable<FileSavePickerContinuationEventArgs>
{
public void LoadNavigationState(WrappedLoadStateEventArgs args)
{
}
public void SaveNavigationState(WrappedSaveStateEventArgs args)
{
}
public async void ButtonClicked()
{
var resp = await this.Messenger.GetResponseAsync(new MessageDialogMessage(
"File Pick Test", "Test Dialog",
new UICommand("OpenPicker"), new UICommand("SavePicker")));
if (resp.ResultIndex == 0)
{
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary
};
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".gif");
picker.FileTypeFilter.Add(".jpg");
picker.PickSingleFileAndContinue();
}
else
{
var picker = new FileSavePicker
{
SuggestedFileName = "photo1",
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
};
picker.FileTypeChoices.Add("Photo File", new[] { ".png", ".gif", ".jpg" });
picker.PickSaveFileAndContinue();
}
}
public async void Continue(FileOpenPickerContinuationEventArgs args)
{
if (args.Files.Count > 0)
{
var file = args.Files[0];
await this.Messenger.GetResponseAsync(new MessageDialogMessage(
"opening file: " + file.Name + " | " + file.Path, "Opening file"));
}
else
{
await this.Messenger.GetResponseAsync(new MessageDialogMessage(
"Cancelled!", "Opening file"));
}
}
public async void Continue(FileSavePickerContinuationEventArgs args)
{
if (args.File != null)
{
var file = args.File;
await this.Messenger.GetResponseAsync(new MessageDialogMessage(
"saving file: " + file.Name + " | " + file.Path, "Saving file"));
}
else
{
await this.Messenger.GetResponseAsync(new MessageDialogMessage(
"Cancelled!", "Saving file"));
}
}
public void Loaded()
{
}
public async void BeginAuth()
{
await this.Messenger.RaiseAsync(new NavigationMessage(typeof(AuthenticationPage)));
}
public bool IsButtonEnabled
{
get { return true; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment