-Fixed CodeRenderer again...
-Made Theme Events a Shell Event, that way Theming behaviour can be overidden. -Added a Theme Picker to the SampleController, with choices of System, Light or Dark for Samples. -Disabled Background Image Switch from Sample Controller, as Background were too distracting and broke many sample Pages. It could possible be brought back in a future PR.
This commit is contained in:
Родитель
fe570aa485
Коммит
dd6ac39711
|
@ -13,7 +13,6 @@
|
|||
using System;
|
||||
using ColorCode;
|
||||
using Microsoft.Toolkit.Uwp.Helpers;
|
||||
using Microsoft.Toolkit.Uwp.UI.Helpers;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.UI.Xaml;
|
||||
|
@ -23,7 +22,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
|
|||
{
|
||||
public class CodeRenderer : Control
|
||||
{
|
||||
private ThemeListener themeListener;
|
||||
private RichTextBlockFormatter _formatter;
|
||||
private RichTextBlock _codeView;
|
||||
private Button _printButton;
|
||||
|
@ -34,13 +32,13 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
|
|||
private string _displayedText;
|
||||
private ILanguage _language;
|
||||
private bool _rendered;
|
||||
private ElementTheme _theme;
|
||||
|
||||
public CodeRenderer()
|
||||
{
|
||||
DefaultStyleKey = typeof(CodeRenderer);
|
||||
|
||||
themeListener = new ThemeListener();
|
||||
themeListener.ThemeChanged += ThemeListener_ThemeChanged;
|
||||
_theme = Shell.Current.GetCurrentTheme();
|
||||
Shell.Current.ThemeChanged += Current_ThemeChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -98,13 +96,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
|
|||
private void RenderDocument()
|
||||
{
|
||||
_codeView?.Blocks?.Clear();
|
||||
var theme = themeListener.CurrentTheme == ApplicationTheme.Dark ? ElementTheme.Dark : ElementTheme.Light;
|
||||
if (RequestedTheme != ElementTheme.Default)
|
||||
{
|
||||
theme = RequestedTheme;
|
||||
}
|
||||
|
||||
_formatter = new RichTextBlockFormatter(theme);
|
||||
_formatter = new RichTextBlockFormatter(_theme);
|
||||
_formatter.FormatRichTextBlock(_displayedText, _language, _codeView);
|
||||
_rendered = true;
|
||||
}
|
||||
|
@ -170,8 +162,9 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.Controls
|
|||
ReleasePrintHelper();
|
||||
}
|
||||
|
||||
private void ThemeListener_ThemeChanged(ThemeListener sender)
|
||||
private void Current_ThemeChanged(object sender, Models.ThemeChangedArgs e)
|
||||
{
|
||||
_theme = e.Theme;
|
||||
try
|
||||
{
|
||||
_rendered = false;
|
||||
|
|
|
@ -16,8 +16,13 @@
|
|||
<Grid x:Name="Container"
|
||||
Grid.RowSpan="2"
|
||||
Opacity="0" />
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<RichTextBlock Name="codeView" />
|
||||
<ScrollViewer
|
||||
Grid.Row="0"
|
||||
HorizontalScrollMode="Auto"
|
||||
HorizontalScrollBarVisibility="Auto">
|
||||
<RichTextBlock Name="codeView"
|
||||
FontFamily="Consolas"
|
||||
Padding="10" />
|
||||
</ScrollViewer>
|
||||
<StackPanel Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
|
|
|
@ -527,6 +527,7 @@
|
|||
<Compile Include="Models\LandingPageLink.cs" />
|
||||
<Compile Include="Models\PaneState.cs" />
|
||||
<Compile Include="Models\PropertyDescriptor\ThicknessPropertyOptions.cs" />
|
||||
<Compile Include="Models\ThemeChangedArgs.cs" />
|
||||
<Compile Include="Pages\SampleController.xaml.cs">
|
||||
<DependentUpon>SampleController.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace Microsoft.Toolkit.Uwp.SampleApp.Models
|
||||
{
|
||||
public class ThemeChangedArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Current UI Theme
|
||||
/// </summary>
|
||||
public ElementTheme Theme { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Theme was set by the User.
|
||||
/// </summary>
|
||||
public bool CustomSet { get; internal set; }
|
||||
}
|
||||
}
|
|
@ -66,11 +66,22 @@
|
|||
|
||||
<AppBarSeparator Margin="-10, 3, -10, 0" />
|
||||
|
||||
<ToggleSwitch x:Name="BGSwitch"
|
||||
Margin="10,0,0,0"
|
||||
<!-- Sample Display properties -->
|
||||
<StackPanel Margin="10,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<!-- Disabled for Possible Future PR -->
|
||||
<ToggleSwitch x:Name="BGSwitch"
|
||||
Visibility="Collapsed"
|
||||
OffContent="BG Image"
|
||||
OnContent="BG Image"
|
||||
IsOn="{x:Bind UseBackground, Mode=TwoWay}" />
|
||||
|
||||
<TextBlock Text="Theme" VerticalAlignment="Center" Margin="0,0,10,0" />
|
||||
<ComboBox x:Name="ThemePicker" SelectedIndex="0" SelectionChanged="ThemePicker_SelectionChanged">
|
||||
<ComboBoxItem Content="System" />
|
||||
<ComboBoxItem Content="Light" />
|
||||
<ComboBoxItem Content="Dark" />
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<AppBarButton x:Name="NarrowInfoButton"
|
||||
|
|
|
@ -21,7 +21,6 @@ using Microsoft.Toolkit.Uwp.SampleApp.Controls;
|
|||
using Microsoft.Toolkit.Uwp.SampleApp.Models;
|
||||
using Microsoft.Toolkit.Uwp.UI.Controls;
|
||||
using Microsoft.Toolkit.Uwp.UI.Extensions;
|
||||
using Microsoft.Toolkit.Uwp.UI.Helpers;
|
||||
using Windows.System;
|
||||
using Windows.System.Profile;
|
||||
using Windows.UI.Core;
|
||||
|
@ -91,7 +90,9 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
{
|
||||
this.InitializeComponent();
|
||||
Current = this;
|
||||
Shell.Current.ThemeChanged += Current_ThemeChanged;
|
||||
|
||||
DocumentationTextblock.RequestedTheme = Shell.Current.GetCurrentTheme();
|
||||
DocumentationTextblock.SetRenderer<SampleAppMarkdownRenderer>();
|
||||
|
||||
ProcessSampleEditorTime();
|
||||
|
@ -573,5 +574,18 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
VisualStateManager.GoToState(this, NarrowState.Name, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Current_ThemeChanged(object sender, ThemeChangedArgs e)
|
||||
{
|
||||
if (e.CustomSet)
|
||||
{
|
||||
DocumentationTextblock.RequestedTheme = e.Theme;
|
||||
}
|
||||
}
|
||||
|
||||
private void ThemePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Shell.Current.SetCurrentTheme((ElementTheme)ThemePicker.SelectedIndex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,20 +29,23 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
|
|||
public sealed partial class MarkdownTextBlockPage : Page, IXamlRenderListener
|
||||
{
|
||||
private TextBox unformattedText;
|
||||
private MarkdownTextBlock markdownText;
|
||||
|
||||
public MarkdownTextBlockPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Shell.Current.ThemeChanged += Current_ThemeChanged;
|
||||
}
|
||||
|
||||
public void OnXamlRendered(FrameworkElement control)
|
||||
{
|
||||
unformattedText = control.FindChildByName("UnformattedText") as TextBox;
|
||||
|
||||
var markdownText = control.FindChildByName("MarkdownText") as MarkdownTextBlock;
|
||||
markdownText = control.FindChildByName("MarkdownText") as MarkdownTextBlock;
|
||||
|
||||
if (markdownText != null)
|
||||
{
|
||||
markdownText.RequestedTheme = Shell.Current.GetCurrentTheme();
|
||||
markdownText.LinkClicked += MarkdownText_LinkClicked;
|
||||
markdownText.ImageClicked += MarkdownText_ImageClicked;
|
||||
markdownText.CodeBlockResolving += MarkdownText_CodeBlockResolving;
|
||||
|
@ -52,6 +55,14 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
|
|||
LoadData();
|
||||
}
|
||||
|
||||
private void Current_ThemeChanged(object sender, Models.ThemeChangedArgs e)
|
||||
{
|
||||
if (e.CustomSet)
|
||||
{
|
||||
markdownText.RequestedTheme = e.Theme;
|
||||
}
|
||||
}
|
||||
|
||||
private async void MarkdownText_ImageClicked(object sender, LinkClickedEventArgs e)
|
||||
{
|
||||
if (!Uri.TryCreate(e.Link, UriKind.Absolute, out Uri result))
|
||||
|
|
|
@ -14,9 +14,11 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Toolkit.Uwp.Helpers;
|
||||
using Microsoft.Toolkit.Uwp.SampleApp.Models;
|
||||
using Microsoft.Toolkit.Uwp.SampleApp.Pages;
|
||||
using Microsoft.Toolkit.Uwp.UI.Controls;
|
||||
using Microsoft.Toolkit.Uwp.UI.Extensions;
|
||||
using Microsoft.Toolkit.Uwp.UI.Helpers;
|
||||
using Windows.Foundation.Metadata;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
|
@ -35,6 +37,12 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
InitializeComponent();
|
||||
Current = this;
|
||||
|
||||
_themeListener = new ThemeListener();
|
||||
_themeListener.ThemeChanged += (s) =>
|
||||
{
|
||||
ThemeChanged?.Invoke(this, new ThemeChangedArgs { Theme = GetCurrentTheme() });
|
||||
};
|
||||
|
||||
var background = new Image()
|
||||
{
|
||||
Source = new BitmapImage(new Uri("ms-appx:///Assets/Photos/Backgrounds/HERO.jpg")),
|
||||
|
@ -72,6 +80,31 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Current UI Theme.
|
||||
/// </summary>
|
||||
/// <returns>The Current UI Theme</returns>
|
||||
public ElementTheme GetCurrentTheme()
|
||||
{
|
||||
return RequestedTheme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Current UI Theme.
|
||||
/// </summary>
|
||||
/// <param name="theme">Theme to set</param>
|
||||
public void SetCurrentTheme(ElementTheme theme)
|
||||
{
|
||||
RequestedTheme = theme;
|
||||
var args = new ThemeChangedArgs
|
||||
{
|
||||
CustomSet = true,
|
||||
Theme = GetCurrentTheme()
|
||||
};
|
||||
|
||||
ThemeChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public void NavigateToSample(Sample sample)
|
||||
{
|
||||
NavigationFrame.Navigate(typeof(SampleController), sample);
|
||||
|
@ -198,5 +231,9 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
}
|
||||
|
||||
private UIElement _parallaxView;
|
||||
|
||||
private ThemeListener _themeListener;
|
||||
|
||||
public event EventHandler<ThemeChangedArgs> ThemeChanged;
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче