Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,10 @@
<Project>{cb444381-18ba-4a51-bb32-3a498bcc1e99}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.Layout</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls.Markdown\Microsoft.Toolkit.Uwp.UI.Controls.Markdown.csproj">
<Project>{6fedf199-b052-49dd-8f3e-2a9224998e0f}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.Markdown</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls\Microsoft.Toolkit.Uwp.UI.Controls.csproj">
<Project>{e9faabfb-d726-42c1-83c1-cb46a29fea81}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls</Name>
Expand Down
12 changes: 12 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,18 @@ private static Type LookForTypeByName(string typeName)
}
}

// Search in Microsoft.Toolkit.Uwp.UI.Controls.Markdown
var markdownTextBlockType = typeof(MarkdownTextBlock);
assembly = markdownTextBlockType.GetTypeInfo().Assembly;

foreach (var typeInfo in assembly.ExportedTypes)
{
if (typeInfo.Name == typeName)
{
return typeInfo;
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// See the LICENSE file in the project root for more information.

using System;
using Windows.UI;
using Microsoft.Toolkit.Uwp.SampleApp.Enums;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Microsoft.Toolkit.Uwp.SampleApp.Enums;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using System;
using System.Collections.Generic;
using System.Windows.Input;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.MarkdownParserPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.MarkdownParser"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TextToolbarSamples
{
public class SampleFormatter : Formatter
{
public SampleFormatter(TextToolbar model)
: base(model)
public override void SetModel(TextToolbar model)
{
base.SetModel(model);

CommonButtons = new CommonButtons(model);
}

Expand All @@ -31,6 +32,6 @@ public override ButtonMap DefaultButtons
}
}

private CommonButtons CommonButtons { get; }
private CommonButtons CommonButtons { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
xmlns:common="using:Microsoft.Toolkit.Uwp.SampleApp.Common"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:markDown="using:Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown"
xmlns:richText="using:Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText"
xmlns:textToolbarSamples="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TextToolbarSamples"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"
mc:Ignorable="d">

<Page.Resources>
<converters:ToolbarFormatActiveConverter x:Key="IsFormatMarkdown"
Format="MarkDown" />
<converters:TypeToObjectConverter x:Key="IsMarkdownFormatter"
Type="markDown:MarkDownFormatter">
<converters:TypeToObjectConverter.TrueValue>
<Visibility>Visible</Visibility>
</converters:TypeToObjectConverter.TrueValue>
<converters:TypeToObjectConverter.FalseValue>
<Visibility>Collapsed</Visibility>
</converters:TypeToObjectConverter.FalseValue>
</converters:TypeToObjectConverter>
</Page.Resources>

<Grid x:Name="MainGrid"
Expand All @@ -22,9 +32,15 @@
<controls:TextToolbar x:Name="Toolbar"
Editor="{Binding ElementName=EditZone}"
IsEnabled="@[IsEnabled:Bool:True]"
Format="@[Format:Enum:Format.RichText]@"
UseURIChecker="@[UseURIChecker:Bool:True]"
Background="#4C4F4F4F" />
Background="#4C4F4F4F">
<controls:TextToolbar.Formatter>
<!-- Choose one -->
<richText:RichTextFormatter />
<!--<markDown:MarkDownFormatter />-->
<!--<textToolbarSamples:SampleFormatter />-->
</controls:TextToolbar.Formatter>
</controls:TextToolbar>

<ScrollViewer Grid.Row="1">
<Grid>
Expand All @@ -46,7 +62,7 @@
<Grid x:Name="MD"
Grid.Row="1"
Margin="0, 16"
Visibility="{Binding Format, ElementName=Toolbar, Mode=OneWay, Converter={StaticResource IsFormatMarkdown}}">
Visibility="{Binding Formatter, ElementName=Toolbar, Mode=OneWay, Converter={StaticResource IsMarkdownFormatter}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ private void EditZone_TextChanged(object sender, Windows.UI.Xaml.RoutedEventArgs

private void UseCustomFormatter()
{
var formatter = new SampleFormatter(Toolbar);
Toolbar.Format = UI.Controls.TextToolbarFormats.Format.Custom;
Toolbar.Formatter = formatter;
Toolbar.Formatter = new SampleFormatter();
}

private int DemoCounter { get; set; } = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:markDown="using:Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown"
xmlns:richText="using:Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText"
xmlns:textToolbarSamples="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TextToolbarSamples"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<converters:ToolbarFormatActiveConverter x:Key="IsFormatMarkdown"
Format="MarkDown" />
<converters:TypeToObjectConverter x:Key="IsMarkdownFormatter"
Type="markDown:MarkDownFormatter">
<converters:TypeToObjectConverter.TrueValue>
<Visibility>Visible</Visibility>
</converters:TypeToObjectConverter.TrueValue>
<converters:TypeToObjectConverter.FalseValue>
<Visibility>Collapsed</Visibility>
</converters:TypeToObjectConverter.FalseValue>
</converters:TypeToObjectConverter>
</Page.Resources>

<Grid>
<controls:TextToolbar />
<controls:TextToolbar>
<controls:TextToolbar.Formatter>
<richText:RichTextFormatter />
</controls:TextToolbar.Formatter>
</controls:TextToolbar>
<controls:TextToolbar>
<controls:TextToolbar.Formatter>
<markDown:MarkDownFormatter />
</controls:TextToolbar.Formatter>
</controls:TextToolbar>
<controls:TextToolbar>
<controls:TextToolbar.Formatter>
<textToolbarSamples:SampleFormatter />
</controls:TextToolbar.Formatter>
</controls:TextToolbar>
<RichEditBox />
<controls:MarkdownTextBlock />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.SampleApp.Models;
using Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TextToolbarSamples;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.System;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -43,11 +40,6 @@ public void OnXamlRendered(FrameworkElement control)
_previewer = previewer;
_previewer.LinkClicked += Previewer_LinkClicked;
}

if (ToolbarFormat != null && (Format)ToolbarFormat.Value == Format.Custom)
{
UseCustomFormatter();
}
}

private void Load()
Expand All @@ -66,6 +58,16 @@ private void Load()
AddCustomButton();
});

SampleController.Current.RegisterNewCommand("Use RichText Formatter", (sender, args) =>
{
UseRichTextFormatter();
});

SampleController.Current.RegisterNewCommand("Use MarkDown Formatter", (sender, args) =>
{
UseMarkDownFormatter();
});

SampleController.Current.RegisterNewCommand("Use Custom Formatter", (sender, args) =>
{
UseCustomFormatter();
Expand Down Expand Up @@ -97,16 +99,34 @@ private void ResetLayout()
}
}

private void UseRichTextFormatter()
{
if (_toolbar == null)
{
return;
}

_toolbar.Formatter = new RichTextFormatter();
}

private void UseMarkDownFormatter()
{
if (_toolbar == null)
{
return;
}

_toolbar.Formatter = new MarkDownFormatter();
}

private void UseCustomFormatter()
{
if (_toolbar == null || ToolbarFormat == null)
if (_toolbar == null)
{
return;
}

var formatter = new SampleFormatter(_toolbar);
ToolbarFormat.Value = Format.Custom;
_toolbar.Formatter = formatter;
_toolbar.Formatter = new SampleFormatter();
}

private void AddCustomButton()
Expand Down Expand Up @@ -179,21 +199,5 @@ private void EditZone_TextChanged(object sender, RoutedEventArgs e)
}

private int DemoCounter { get; set; } = 0;

private ValueHolder ToolbarFormat
{
get
{
if (DataContext is Sample sample)
{
if (sample.PropertyDescriptor.Expando is IDictionary<string, object> properties && properties.TryGetValue("Format", out var format))
{
return format as ValueHolder;
}
}

return null;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void AddDescriptions(AttributeTableBuilder builder)
try
{
string name = (string)member.Attribute("name");
if (name == null)
if (name == null)
continue;
bool isType = name.StartsWith("T:", StringComparison.OrdinalIgnoreCase);
if (isType ||
Expand All @@ -123,7 +123,7 @@ private void AddDescriptions(AttributeTableBuilder builder)
typeName = name.Substring(2, lastDot - 2);
}
typeName += AssemblyFullName;

Type t = Type.GetType(typeName);
if (t != null && t.IsPublic && t.IsClass &&
t.IsSubclassOf(Types.PlatformTypes.DependencyObjectType))
Expand Down Expand Up @@ -164,7 +164,7 @@ private void AddDescriptions(AttributeTableBuilder builder)
isBrowsable = IsBrowsable(pi);
}
catch { isBrowsable = false; }
if(isBrowsable)
if (isBrowsable)
builder.AddCallback(t, b => b.AddCustomAttributes(propName, new DescriptionAttribute(desc)));
else //Hide from intellisense
builder.AddCallback(t, b => b.AddCustomAttributes(new BrowsableAttribute(false)));
Expand Down
Loading