Skip to content

Commit

Permalink
Merge pull request #1392 from Microsoft/sampleAppFixes
Browse files Browse the repository at this point in the history
Sample app fixes
  • Loading branch information
IbraheemOsama authored Aug 21, 2017
2 parents 6f38b9f + d9efb08 commit 03b59d3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private async void PrintButton_Click(object sender, RoutedEventArgs e)

_printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
_printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
_printHelper.OnPrintCanceled += PrinteHelper_OnPrintCanceled;

await _printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App");
}
Expand All @@ -160,6 +161,11 @@ private void ReleasePrintHelper()
{
_webView.Width = double.NaN;
_webView.Height = double.NaN;

_printHelper.OnPrintFailed -= PrintHelper_OnPrintFailed;
_printHelper.OnPrintSucceeded -= PrintHelper_OnPrintSucceeded;
_printHelper.OnPrintCanceled -= PrinteHelper_OnPrintCanceled;

_printHelper.Dispose();

Shell.Current.DisplayWaitRing = false;
Expand All @@ -179,6 +185,11 @@ private async void PrintHelper_OnPrintFailed()
await dialog.ShowAsync();
}

private void PrinteHelper_OnPrintCanceled()
{
ReleasePrintHelper();
}

private async Task ShowDocument(string docText, string pattern)
{
if (_webView != null)
Expand Down
39 changes: 36 additions & 3 deletions Microsoft.Toolkit.Uwp.SampleApp/Controls/PropertyControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Toolkit.Uwp.SampleApp.Common;
Expand All @@ -26,10 +27,21 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
{
public sealed partial class PropertyControl
{
private static Dictionary<Color, string> _colorNames;

private Sample _currentSample;

public PropertyControl()
{
if (_colorNames == null)
{
_colorNames = new Dictionary<Color, string>();
foreach (var color in typeof(Colors).GetRuntimeProperties())
{
_colorNames[(Color)color.GetValue(null)] = color.Name;
}
}

InitializeComponent();
}

Expand Down Expand Up @@ -68,6 +80,8 @@ private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataC
DependencyProperty dependencyProperty;
IValueConverter converter = null;

IDictionary<string, object> propertyDict = propertyDesc.Expando;

switch (option.Kind)
{
case PropertyKind.Slider:
Expand All @@ -86,6 +100,11 @@ private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataC
slider.StepFrequency = 0.01;
}

if ((propertyDict[option.Name] as ValueHolder).Value is double value)
{
slider.Value = value;
}

controlToAdd = slider;
dependencyProperty = RangeBase.ValueProperty;

Expand All @@ -95,7 +114,7 @@ private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataC
var comboBox = new ComboBox
{
ItemsSource = Enum.GetNames(enumType),
SelectedItem = option.DefaultValue.ToString()
SelectedItem = (propertyDict[option.Name] as ValueHolder).Value.ToString()
};

converter = new EnumConverter(enumType);
Expand All @@ -105,22 +124,36 @@ private void PropertyControl_OnDataContextChanged(FrameworkElement sender, DataC
case PropertyKind.Bool:
var checkBox = new ToggleSwitch();

if ((propertyDict[option.Name] as ValueHolder).Value is bool isOn)
{
checkBox.IsOn = isOn;
}

controlToAdd = checkBox;
dependencyProperty = ToggleSwitch.IsOnProperty;
break;
case PropertyKind.Brush:
var colorComboBox = new ComboBox();
var dataSource = typeof(Colors).GetTypeInfo().DeclaredProperties.Select(p => p.Name).ToList();
colorComboBox.ItemsSource = dataSource;
colorComboBox.SelectedIndex = dataSource.IndexOf(option.DefaultValue.ToString());

if ((propertyDict[option.Name] as ValueHolder).Value is SolidColorBrush brush &&
_colorNames.TryGetValue(brush.Color, out var color))
{
colorComboBox.SelectedIndex = dataSource.IndexOf(color);
}
else
{
colorComboBox.SelectedIndex = dataSource.IndexOf(option.DefaultValue.ToString());
}

converter = new SolidColorBrushConverter();

controlToAdd = colorComboBox;
dependencyProperty = Selector.SelectedItemProperty;
break;
default:
var textBox = new TextBox { Text = option.DefaultValue.ToString() };
var textBox = new TextBox { Text = (propertyDict[option.Name] as ValueHolder).Value.ToString() };

controlToAdd = textBox;
dependencyProperty = TextBox.TextProperty;
Expand Down

0 comments on commit 03b59d3

Please sign in to comment.