Files
UWP-Visual-Asset-Generator/UserControls/SidebarUserControl.xaml.cs

104 lines
3.5 KiB
C#
Raw Permalink Normal View History

2019-09-19 12:34:02 +10:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
2019-11-20 06:11:57 +11:00
using System.Threading.Tasks;
using UWP_Visual_Asset_Generator.ViewModels;
using Windows.ApplicationModel.DataTransfer;
2019-09-19 12:34:02 +10:00
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
2019-09-19 12:34:02 +10:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace UWP_Visual_Asset_Generator.UserControls
{
public sealed partial class SidebarUserControl : UserControl
{
public MainViewModel mainViewModel { get; set; }
2019-09-19 12:34:02 +10:00
public SidebarUserControl()
{
this.InitializeComponent();
mainViewModel = App.mainViewModel;
2019-09-19 12:34:02 +10:00
}
2020-07-21 08:26:53 +10:00
private async void Image_Original_Tapped(object sender, TappedRoutedEventArgs e)
{
2020-07-21 08:26:53 +10:00
await mainViewModel.LoadOriginalImageFromFileAsync();
}
private async void Image_Original_Drop(object sender, DragEventArgs e)
{
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await e.DataView.GetStorageItemsAsync();
if (items.Count > 0 &&
items[0] is StorageFile &&
((StorageFile)items[0]).FileType.ToLower().Equals(".png"))
{
mainViewModel.LoadOriginalImageFromFileAsync(items[0] as StorageFile);
}
else
{
mainViewModel.ShowDialog("Information", "Only .PNG files are allowed.");
}
}
}
private void Image_Original_DragOver(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Link;
e.DragUIOverride.Caption = "Load file"; // Sets custom UI text
//e.DragUIOverride.SetContentFromBitmapImage(null); // Sets a custom glyph
e.DragUIOverride.IsCaptionVisible = true; // Sets if the caption is visible
e.DragUIOverride.IsContentVisible = true; // Sets if the dragged content is visible
e.DragUIOverride.IsGlyphVisible = true; // Sets if the glyph is visibile
}
private void Btn_OutputFolder_Click(object sender, RoutedEventArgs e)
{
mainViewModel.SetOutputFolderAsync();
}
2019-11-20 06:11:57 +11:00
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var s = sender as ComboBox;
if (s != null)
{
SetThemeAsync(s.SelectedIndex);
}
}
public async Task SetThemeAsync(int theme)
{
2020-07-21 08:26:53 +10:00
if (App.mainPage != null)
2019-11-20 06:11:57 +11:00
{
2020-07-21 08:26:53 +10:00
switch (theme)
{
case 0: App.mainPage.RequestedTheme = ElementTheme.Default; ; break;
case 1: App.mainPage.RequestedTheme = ElementTheme.Light; ; break;
case 2: App.mainPage.RequestedTheme = ElementTheme.Dark; ; break;
}
2019-11-20 06:11:57 +11:00
}
}
private async void btnSetBackgroundColour_Click(object sender, RoutedEventArgs e)
{
var dialog = new BackgroundColorUserControl();
await dialog.ShowAsync();
}
2019-09-19 12:34:02 +10:00
}
}