Skip to content

Commit 21b9988

Browse files
authored
Merge pull request #629 from Microsoft/dev
Merging 1.2 to master
2 parents 77f9a34 + 0267b96 commit 21b9988

File tree

372 files changed

+11419
-4889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+11419
-4889
lines changed
-28.8 KB
Binary file not shown.
Lines changed: 119 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,130 @@
1-
<Application
2-
x:Class="Microsoft.Toolkit.Uwp.SampleApp.App"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp"
6-
xmlns:controls="using:Microsoft.Toolkit.Uwp.SampleApp.Controls"
7-
RequestedTheme="Light">
8-
9-
<Application.Resources>
10-
11-
<!-- Colors -->
12-
<Color x:Key="Grey-01">#FF333333</Color>
13-
<Color x:Key="Grey-02">#FF444444</Color>
14-
<Color x:Key="Grey-03">#FF555555</Color>
15-
<Color x:Key="Grey-04">#FFDDDDDD</Color>
16-
<Color x:Key="Grey-05">#FFF0F0F0</Color>
17-
<Color x:Key="White">#FFFFFFFF</Color>
1+
<Application x:Class="Microsoft.Toolkit.Uwp.SampleApp.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:controls="using:Microsoft.Toolkit.Uwp.SampleApp.Controls"
5+
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp"
6+
RequestedTheme="Light">
187

19-
<Color x:Key="Blue-01">#FF0078D7</Color>
8+
<Application.Resources>
209

21-
<!-- Brushes -->
22-
<SolidColorBrush x:Key="Brush-Grey-01" Color="{StaticResource Grey-01}"/>
23-
<SolidColorBrush x:Key="Brush-Grey-02" Color="{StaticResource Grey-02}"/>
24-
<SolidColorBrush x:Key="Brush-Grey-03" Color="{StaticResource Grey-03}"/>
25-
<SolidColorBrush x:Key="Brush-Grey-04" Color="{StaticResource Grey-04}"/>
26-
<SolidColorBrush x:Key="Brush-Grey-05" Color="{StaticResource Grey-05}"/>
27-
<SolidColorBrush x:Key="Brush-White" Color="{StaticResource White}"/>
10+
<!-- Colors -->
11+
<Color x:Key="Grey-01">#FF333333</Color>
12+
<Color x:Key="Grey-02">#FF444444</Color>
13+
<Color x:Key="Grey-03">#FF555555</Color>
14+
<Color x:Key="Grey-04">#FFDDDDDD</Color>
15+
<Color x:Key="Grey-05">#FFF0F0F0</Color>
16+
<Color x:Key="White">#FFFFFFFF</Color>
2817

29-
<SolidColorBrush x:Key="Brush-Blue-01" Color="{StaticResource Blue-01}"/>
18+
<Color x:Key="Blue-01">#FF0078D7</Color>
3019

31-
<!-- Styles -->
20+
<!-- Brushes -->
21+
<SolidColorBrush x:Key="Brush-Grey-01"
22+
Color="{StaticResource Grey-01}" />
23+
<SolidColorBrush x:Key="Brush-Grey-02"
24+
Color="{StaticResource Grey-02}" />
25+
<SolidColorBrush x:Key="Brush-Grey-03"
26+
Color="{StaticResource Grey-03}" />
27+
<SolidColorBrush x:Key="Brush-Grey-04"
28+
Color="{StaticResource Grey-04}" />
29+
<SolidColorBrush x:Key="Brush-Grey-05"
30+
Color="{StaticResource Grey-05}" />
31+
<SolidColorBrush x:Key="Brush-White"
32+
Color="{StaticResource White}" />
3233

33-
<Style TargetType="TextBlock">
34-
<Setter Property="Foreground" Value="{StaticResource Brush-Grey-01}"/>
35-
</Style>
34+
<SolidColorBrush x:Key="Brush-Blue-01"
35+
Color="{StaticResource Blue-01}" />
3636

37-
<Style TargetType="Button">
38-
<Setter Property="Foreground" Value="{StaticResource Brush-Grey-01}"/>
39-
</Style>
40-
41-
42-
<Style TargetType="controls:CodeRenderer">
43-
<Setter Property="Template">
44-
<Setter.Value>
45-
<ControlTemplate TargetType="controls:CodeRenderer">
46-
<Grid>
47-
<ProgressRing Name="progress" Width="100" Height="100" Foreground="{TemplateBinding Foreground}"
48-
IsActive="True" VerticalAlignment="Center" HorizontalAlignment="Center"/>
49-
<WebView Name="webView" Visibility="Collapsed"/>
50-
</Grid>
51-
</ControlTemplate>
52-
</Setter.Value>
53-
</Setter>
54-
</Style>
37+
<!-- Styles -->
5538

56-
<Style x:Key="TooltipFlyoutPresenterStyle" TargetType="FlyoutPresenter">
57-
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
58-
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
59-
<Setter Property="IsTabStop" Value="False"/>
60-
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}"/>
61-
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeHighBrush}"/>
62-
<Setter Property="BorderThickness" Value="{ThemeResource FlyoutBorderThemeThickness}"/>
63-
<Setter Property="Padding" Value="0"/>
64-
<Setter Property="MinWidth" Value="{ThemeResource FlyoutThemeMinWidth}"/>
65-
<Setter Property="MaxWidth" Value="{ThemeResource FlyoutThemeMaxHeight}"/>
66-
<Setter Property="MinHeight" Value="{ThemeResource FlyoutThemeMinHeight}"/>
67-
<Setter Property="MaxHeight" Value="{ThemeResource FlyoutThemeMaxHeight}"/>
68-
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled"/>
69-
<Setter Property="Template">
70-
<Setter.Value>
71-
<ControlTemplate TargetType="FlyoutPresenter">
72-
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="5">
73-
<ScrollViewer x:Name="ScrollViewer" AutomationProperties.AccessibilityView="Raw" HorizontalScrollMode="Disabled" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto" ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
74-
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
75-
</ScrollViewer>
76-
</Border>
77-
</ControlTemplate>
78-
</Setter.Value>
79-
</Setter>
80-
</Style>
81-
<DataTemplate x:Key="PivotHeaderTemplate">
39+
<Style TargetType="TextBlock">
40+
<Setter Property="Foreground" Value="{StaticResource Brush-Grey-01}" />
41+
</Style>
42+
43+
<Style TargetType="Button">
44+
<Setter Property="Foreground" Value="{StaticResource Brush-Grey-01}" />
45+
</Style>
46+
47+
48+
<Style TargetType="controls:CodeRenderer">
49+
<Setter Property="Template">
50+
<Setter.Value>
51+
<ControlTemplate TargetType="controls:CodeRenderer">
8252
<Grid>
83-
<TextBlock Text="{Binding}" FontSize="14"/>
53+
<Grid.RowDefinitions>
54+
<RowDefinition />
55+
<RowDefinition Height="Auto" />
56+
</Grid.RowDefinitions>
57+
<Grid x:Name="Container"
58+
Grid.RowSpan="2"
59+
Opacity="0" />
60+
<ProgressRing Name="progress"
61+
Grid.Row="0"
62+
Width="100"
63+
Height="100"
64+
HorizontalAlignment="Center"
65+
VerticalAlignment="Center"
66+
Foreground="{TemplateBinding Foreground}"
67+
IsActive="True" />
68+
<WebView Name="webView"
69+
Grid.Row="0"
70+
Visibility="Collapsed" />
71+
<Button x:Name="PrintButton"
72+
Grid.Row="1"
73+
Margin="5"
74+
HorizontalAlignment="Center"
75+
Content="Print" />
8476
</Grid>
85-
</DataTemplate>
86-
</Application.Resources>
77+
</ControlTemplate>
78+
</Setter.Value>
79+
</Setter>
80+
</Style>
81+
82+
<Style x:Key="TooltipFlyoutPresenterStyle"
83+
TargetType="FlyoutPresenter">
84+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
85+
<Setter Property="VerticalContentAlignment" Value="Stretch" />
86+
<Setter Property="IsTabStop" Value="False" />
87+
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" />
88+
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeHighBrush}" />
89+
<Setter Property="BorderThickness" Value="{ThemeResource FlyoutBorderThemeThickness}" />
90+
<Setter Property="Padding" Value="0" />
91+
<Setter Property="MinWidth" Value="{ThemeResource FlyoutThemeMinWidth}" />
92+
<Setter Property="MaxWidth" Value="{ThemeResource FlyoutThemeMaxHeight}" />
93+
<Setter Property="MinHeight" Value="{ThemeResource FlyoutThemeMinHeight}" />
94+
<Setter Property="MaxHeight" Value="{ThemeResource FlyoutThemeMaxHeight}" />
95+
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
96+
<Setter Property="Template">
97+
<Setter.Value>
98+
<ControlTemplate TargetType="FlyoutPresenter">
99+
<Border Margin="5"
100+
Background="{TemplateBinding Background}"
101+
BorderBrush="{TemplateBinding BorderBrush}"
102+
BorderThickness="{TemplateBinding BorderThickness}">
103+
<ScrollViewer x:Name="ScrollViewer"
104+
AutomationProperties.AccessibilityView="Raw"
105+
HorizontalScrollBarVisibility="Disabled"
106+
HorizontalScrollMode="Disabled"
107+
VerticalScrollBarVisibility="Auto"
108+
VerticalScrollMode="Auto"
109+
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
110+
<ContentPresenter Margin="{TemplateBinding Padding}"
111+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
112+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
113+
Content="{TemplateBinding Content}"
114+
ContentTemplate="{TemplateBinding ContentTemplate}"
115+
ContentTransitions="{TemplateBinding ContentTransitions}" />
116+
</ScrollViewer>
117+
</Border>
118+
</ControlTemplate>
119+
</Setter.Value>
120+
</Setter>
121+
</Style>
122+
<DataTemplate x:Key="PivotHeaderTemplate">
123+
<Grid>
124+
<TextBlock FontSize="14"
125+
Text="{Binding}" />
126+
</Grid>
127+
</DataTemplate>
128+
</Application.Resources>
87129

88130
</Application>

Microsoft.Toolkit.Uwp.SampleApp/App.xaml.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,9 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
6262
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
6363
{
6464
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
65-
Color blueBrush = default(Color);
66-
Color lightGreyBrush = default(Color);
67-
Color greyBrush03 = default(Color);
68-
Color greyBrush01 = default(Color);
69-
blueBrush = (Color)Resources["Blue-01"];
70-
lightGreyBrush = (Color)Resources["Grey-04"];
71-
greyBrush03 = (Color)Resources["Grey-03"];
72-
greyBrush01 = (Color)Resources["Grey-01"];
65+
var lightGreyBrush = (Color)Resources["Grey-04"];
66+
var greyBrush03 = (Color)Resources["Grey-03"];
67+
var greyBrush01 = (Color)Resources["Grey-01"];
7368

7469
if (titleBar != null)
7570
{
19.3 KB
Loading

Microsoft.Toolkit.Uwp.SampleApp/Controls/CodeRenderer/CodeRenderer.cs

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@
1515
using System.Threading.Tasks;
1616
using System.Xml;
1717
using System.Xml.Linq;
18-
1918
using Newtonsoft.Json;
20-
2119
using Windows.Storage;
20+
using Windows.UI.Popups;
2221
using Windows.UI.Xaml;
2322
using Windows.UI.Xaml.Controls;
23+
using Windows.UI.Xaml.Media;
2424
using Windows.UI.Xaml.Navigation;
25+
using Windows.UI.Xaml.Shapes;
2526

2627
namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
2728
{
2829
public partial class CodeRenderer : Control
2930
{
3031
private ProgressRing _progress;
3132
private WebView _webView;
33+
private Button _printButton;
34+
private PrintHelper _printHelper;
35+
private Grid _container;
3236

3337
private bool _isInitialized;
3438

@@ -44,14 +48,26 @@ protected override void OnApplyTemplate()
4448
_webView.LoadCompleted -= OnLoadCompleted;
4549
}
4650

51+
if (_printButton != null)
52+
{
53+
_printButton.Click -= PrintButton_Click;
54+
}
55+
4756
_progress = GetTemplateChild("progress") as ProgressRing;
4857
_webView = GetTemplateChild("webView") as WebView;
58+
_printButton = GetTemplateChild("PrintButton") as Button;
59+
_container = GetTemplateChild("Container") as Grid;
4960

5061
if (_webView != null)
5162
{
5263
_webView.LoadCompleted += OnLoadCompleted;
5364
}
5465

66+
if (_printButton != null)
67+
{
68+
_printButton.Click += PrintButton_Click;
69+
}
70+
5571
_isInitialized = true;
5672

5773
SetHtmlSource(HtmlSource);
@@ -63,6 +79,80 @@ protected override void OnApplyTemplate()
6379
base.OnApplyTemplate();
6480
}
6581

82+
private async Task<Rectangle> PrepareWebViewForPrintingAsync()
83+
{
84+
var widthString = await _webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" });
85+
int contentWidth;
86+
87+
if (!int.TryParse(widthString, out contentWidth))
88+
{
89+
throw new Exception(string.Format("failure/width:{0}", widthString));
90+
}
91+
92+
_webView.Width = contentWidth;
93+
94+
// resize height to content
95+
var heightString = await _webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" });
96+
int contentHeight;
97+
98+
if (!int.TryParse(heightString, out contentHeight))
99+
{
100+
throw new Exception(string.Format("failure/height:{0}", heightString));
101+
}
102+
103+
_webView.Height = contentHeight;
104+
105+
WebViewBrush brush = new WebViewBrush();
106+
brush.SetSource(_webView);
107+
brush.Stretch = Stretch.Uniform;
108+
109+
brush.Redraw();
110+
111+
// Send to printer
112+
var rect = new Rectangle();
113+
rect.Fill = brush;
114+
rect.Width = contentWidth;
115+
rect.Height = contentHeight;
116+
117+
return rect;
118+
}
119+
120+
private async void PrintButton_Click(object sender, RoutedEventArgs e)
121+
{
122+
Shell.Current.DisplayWaitRing = true;
123+
124+
_printHelper = new PrintHelper(_container);
125+
_printHelper.AddFrameworkElementToPrint(await PrepareWebViewForPrintingAsync());
126+
127+
_printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
128+
_printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
129+
130+
await _printHelper.ShowPrintUIAsync("UWP Community Toolkit Sample App");
131+
}
132+
133+
private void ReleasePrintHelper()
134+
{
135+
_webView.Width = double.NaN;
136+
_webView.Height = double.NaN;
137+
_printHelper.Dispose();
138+
139+
Shell.Current.DisplayWaitRing = false;
140+
}
141+
142+
private async void PrintHelper_OnPrintSucceeded()
143+
{
144+
ReleasePrintHelper();
145+
var dialog = new MessageDialog("Printing done.");
146+
await dialog.ShowAsync();
147+
}
148+
149+
private async void PrintHelper_OnPrintFailed()
150+
{
151+
ReleasePrintHelper();
152+
var dialog = new MessageDialog("Printing failed.");
153+
await dialog.ShowAsync();
154+
}
155+
66156
private async Task ShowDocument(string docText, string pattern)
67157
{
68158
if (_webView != null)
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
<UserControl
2-
x:Class="Microsoft.Toolkit.Uwp.SampleApp.Controls.PropertyControl"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:Microsoft.Toolkit.UwpSampleApp.Controls"
6-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8-
mc:Ignorable="d"
9-
DataContextChanged="PropertyControl_OnDataContextChanged"
10-
d:DesignHeight="300"
11-
d:DesignWidth="400">
1+
<UserControl x:Class="Microsoft.Toolkit.Uwp.SampleApp.Controls.PropertyControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:local="using:Microsoft.Toolkit.UwpSampleApp.Controls"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="300"
8+
d:DesignWidth="400"
9+
DataContextChanged="PropertyControl_OnDataContextChanged"
10+
mc:Ignorable="d">
1211

13-
<StackPanel x:Name="RootPanel"
14-
Padding="15,20,15,20"
15-
Background="{StaticResource AppBarBackgroundThemeBrush}" />
12+
<StackPanel x:Name="RootPanel"
13+
Padding="15,20,15,20"
14+
Background="{StaticResource AppBarBackgroundThemeBrush}" />
1615
</UserControl>

0 commit comments

Comments
 (0)