Merge branch 'master' into removeObsolete7

This commit is contained in:
Alexandre Zollinger Chohfi 2020-09-10 10:39:18 -07:00 коммит произвёл GitHub
Родитель ba60fb87ee 609430a5f9
Коммит 9eb3de7b6b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
86 изменённых файлов: 2953 добавлений и 509 удалений

Просмотреть файл

@ -509,9 +509,15 @@
<Content Include="SamplePages\ViewportBehavior\ViewportBehaviorCode.bind" />
<Content Include="SamplePages\Weibo Service\WeiboCode.bind" />
<Compile Include="Common\TextBlockHyperlinkBehavior.cs" />
<Compile Include="SamplePages\AutoFocusBehavior\AutoFocusBehaviorPage.xaml.cs">
<DependentUpon>AutoFocusBehaviorPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\EnumValuesExtension\EnumValuesExtensionPage.xaml.cs">
<DependentUpon>EnumValuesExtensionPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\FocusBehavior\FocusBehaviorPage.xaml.cs">
<DependentUpon>FocusBehaviorPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\TilesBrush\TilesBrushPage.xaml.cs">
<DependentUpon>TilesBrushPage.xaml</DependentUpon>
</Compile>
@ -615,6 +621,8 @@
<Content Include="SamplePages\StaggeredLayout\StaggeredLayout.bind" />
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionXaml.bind" />
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionCode.bind" />
<Content Include="SamplePages\FocusBehavior\FocusBehaviorXaml.bind" />
<Content Include="SamplePages\AutoFocusBehavior\AutoFocusBehaviorXaml.bind" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
@ -984,10 +992,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\AutoFocusBehavior\AutoFocusBehaviorPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\EnumValuesExtension\EnumValuesExtensionPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SamplePages\FocusBehavior\FocusBehaviorPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -1512,6 +1528,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>
@ -1545,6 +1565,7 @@
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>

Просмотреть файл

@ -727,6 +727,18 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
}
}
// 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;
}

Просмотреть файл

@ -0,0 +1,21 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.AutoFocusBehaviorPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button Content="I receive the focus when loaded">
<interactivity:Interaction.Behaviors>
<behaviors:AutoFocusBehavior />
</interactivity:Interaction.Behaviors>
</Button>
<Button Content="I do not receive the focus when loaded" />
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// A page that shows how to use the AutoFocusBehavior
/// </summary>
public sealed partial class AutoFocusBehaviorPage : Page
{
public AutoFocusBehaviorPage() => InitializeComponent();
}
}

Просмотреть файл

@ -0,0 +1,20 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button Content="I receive the focus when loaded">
<interactivity:Interaction.Behaviors>
<behaviors:AutoFocusBehavior />
</interactivity:Interaction.Behaviors>
</Button>
<Button Content="I do not receive the focus when loaded" />
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -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
{

Просмотреть файл

@ -0,0 +1,31 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.FocusBehaviorPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<interactivity:Interaction.Behaviors>
<behaviors:FocusBehavior>
<behaviors:FocusTarget Control="{x:Bind disabledItem}" />
<behaviors:FocusTarget Control="{x:Bind emptyList}" />
<behaviors:FocusTarget Control="{x:Bind enabledItem}" />
</behaviors:FocusBehavior>
</interactivity:Interaction.Behaviors>
<StackPanel>
<Button x:Name="disabledItem"
Content="I'm disabled and cannot get the focus"
IsEnabled="False" />
<ListView x:Name="emptyList">
<!--<ListView.Items>
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
</ListView.Items>-->
</ListView>
<Button x:Name="enabledItem"
Content="I can get the focus" />
</StackPanel>
</Page>

Просмотреть файл

@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// A page that shows how to use the FocusBehavior
/// </summary>
public sealed partial class FocusBehaviorPage : Page
{
public FocusBehaviorPage() => InitializeComponent();
}
}

Просмотреть файл

@ -0,0 +1,31 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<interactivity:Interaction.Behaviors>
<behaviors:FocusBehavior>
<behaviors:FocusTarget Control="{x:Bind disabledItem}" />
<behaviors:FocusTarget Control="{x:Bind emptyList}" />
<behaviors:FocusTarget Control="{x:Bind enabledItem}" />
</behaviors:FocusBehavior>
</interactivity:Interaction.Behaviors>
<StackPanel>
<Button x:Name="disabledItem"
Content="I'm disabled and cannot get the focus"
IsEnabled="False" />
<ListView x:Name="emptyList">
<!-- Uncomment this to fill the list and have it receiving the focus
<ListView.Items>
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
</ListView.Items>-->
</ListView>
<Button x:Name="enabledItem"
Content="I can get the focus" />
</StackPanel>
</Page>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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">

Просмотреть файл

@ -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);
}
@ -31,6 +32,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages.TextToolbarSamples
}
}
private CommonButtons CommonButtons { get; }
private CommonButtons CommonButtons { get; set; }
}
}

Просмотреть файл

@ -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"
@ -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>
@ -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 />

Просмотреть файл

@ -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;

Просмотреть файл

@ -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>

Просмотреть файл

@ -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;
@ -43,11 +40,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
_previewer = previewer;
_previewer.LinkClicked += Previewer_LinkClicked;
}
if (ToolbarFormat != null && (Format)ToolbarFormat.Value == Format.Custom)
{
UseCustomFormatter();
}
}
private void Load()
@ -66,6 +58,16 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
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();
@ -97,16 +99,34 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
}
}
private void UseCustomFormatter()
private void UseRichTextFormatter()
{
if (_toolbar == null || ToolbarFormat == null)
if (_toolbar == null)
{
return;
}
var formatter = new SampleFormatter(_toolbar);
ToolbarFormat.Value = Format.Custom;
_toolbar.Formatter = formatter;
_toolbar.Formatter = new RichTextFormatter();
}
private void UseMarkDownFormatter()
{
if (_toolbar == null)
{
return;
}
_toolbar.Formatter = new MarkDownFormatter();
}
private void UseCustomFormatter()
{
if (_toolbar == null)
{
return;
}
_toolbar.Formatter = new SampleFormatter();
}
private void AddCustomButton()
@ -179,21 +199,5 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
}
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;
}
}
}
}
}

Просмотреть файл

@ -841,12 +841,32 @@
"Type": "ViewportBehaviorPage",
"Subcategory": "Systems",
"About": "Behavior for listening element enter or exit viewport",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Animations/ViewportBehavior",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Behaviors",
"CodeFile": "ViewportBehaviorCode.bind",
"XamlCodeFile": "ViewportBehaviorXaml.bind",
"Icon": "/SamplePages/ViewportBehavior/ViewportBehavior.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/animations/ViewportBehavior.md"
},
{
"Name": "AutoFocusBehavior",
"Type": "AutoFocusBehaviorPage",
"Subcategory": "Systems",
"About": "Behavior to automatically set the focus on a control when it loads",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Behaviors/",
"XamlCodeFile": "AutoFocusBehaviorXaml.bind",
"Icon": "/Assets/Helpers.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/behaviors/AutoFocusBehavior.md"
},
{
"Name": "FocusBehavior",
"Type": "FocusBehaviorPage",
"Subcategory": "Systems",
"About": "Behavior to automatically set the focus on the first control which accepts it",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Behaviors/",
"CodeFile": "FocusBehaviorXaml.bind",
"Icon": "/Assets/Helpers.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/behaviors/FocusBehavior.md"
},
{
"Name": "Markdown Parser",
"Type": "MarkdownParserPage",

Просмотреть файл

@ -105,7 +105,7 @@ namespace Microsoft.Toolkit.Uwp.Design.Common
try
{
string name = (string)member.Attribute("name");
if (name == null)
if (name == null)
continue;
bool isType = name.StartsWith("T:", StringComparison.OrdinalIgnoreCase);
if (isType ||
@ -123,7 +123,7 @@ namespace Microsoft.Toolkit.Uwp.Design.Common
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))
@ -164,7 +164,7 @@ namespace Microsoft.Toolkit.Uwp.Design.Common
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)));

Просмотреть файл

@ -15,8 +15,8 @@ using System.Xml.Linq;
namespace Microsoft.Toolkit.Uwp.Design.Common
{
public class MetadataRegistrationBase
{
public class MetadataRegistrationBase
{
private AttributeTable masterMetadataTable;
internal MetadataRegistrationBase() { }
@ -26,227 +26,227 @@ namespace Microsoft.Toolkit.Uwp.Design.Common
/// </summary>
/// <returns>Custom attribute table.</returns>
protected virtual AttributeTable BuildAttributeTable()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
{
AttributeTableBuilder builder = new AttributeTableBuilder();
AddDescriptions(builder);
AddAttributes(builder);
AddTables(builder, this);
masterMetadataTable = builder.CreateTable();
return masterMetadataTable;
}
return masterMetadataTable;
}
/// <summary>
/// Find all AttributeTableBuilder subclasses in the assembly
/// and add their attributes to the assembly attribute table.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail!")]
private void AddTables(AttributeTableBuilder builder, object parent)
{
Debug.Assert(builder != null, "AddTables is called with null parameter!");
/// <summary>
/// Find all AttributeTableBuilder subclasses in the assembly
/// and add their attributes to the assembly attribute table.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail!")]
private void AddTables(AttributeTableBuilder builder, object parent)
{
Debug.Assert(builder != null, "AddTables is called with null parameter!");
Assembly asm = parent.GetType().Assembly;
foreach (Type t in asm.GetTypes())
{
if (t.IsSubclassOf(typeof(AttributeTableBuilder)))
{
try
{
Assembly asm = parent.GetType().Assembly;
foreach (Type t in asm.GetTypes())
{
if (t.IsSubclassOf(typeof(AttributeTableBuilder)))
{
try
{
AttributeTableBuilder atb = (AttributeTableBuilder)Activator.CreateInstance(t);
builder.AddTable(atb.CreateTable());
}
catch (Exception)
{
}
catch (Exception)
{
//error loading design assembly
}
}
}
}
}
}
}
}
/// <summary>
/// Gets or sets the case sensitive resource name of the embedded XML file.
/// </summary>
protected string XmlResourceName { get; set; }
/// <summary>
/// Gets or sets the case sensitive resource name of the embedded XML file.
/// </summary>
protected string XmlResourceName { get; set; }
/// <summary>
/// Gets or sets the FullName of the corresponding run time assembly.
/// </summary>
protected string AssemblyFullName { get; set; }
/// <summary>
/// Gets or sets the FullName of the corresponding run time assembly.
/// </summary>
protected string AssemblyFullName { get; set; }
/// <summary>
/// Create description attribute from run time assembly xml file.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail.")]
private void AddDescriptions(AttributeTableBuilder builder)
{
Debug.Assert(builder != null, "AddDescriptions is called with null parameter!");
/// <summary>
/// Create description attribute from run time assembly xml file.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail.")]
private void AddDescriptions(AttributeTableBuilder builder)
{
Debug.Assert(builder != null, "AddDescriptions is called with null parameter!");
if (string.IsNullOrEmpty(XmlResourceName) ||
string.IsNullOrEmpty(AssemblyFullName))
{
return;
}
XDocument xdoc = null;
try
{
xdoc = XDocument.Load(new StreamReader(
Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlResourceName)));
}
catch { return; }
if (xdoc == null)
{
return;
}
if (string.IsNullOrEmpty(XmlResourceName) ||
string.IsNullOrEmpty(AssemblyFullName))
{
return;
}
XDocument xdoc = null;
try
{
xdoc = XDocument.Load(new StreamReader(
Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlResourceName)));
}
catch { return; }
if (xdoc == null)
{
return;
}
foreach (XElement member in xdoc.Descendants("member"))
{
try
{
string name = (string)member.Attribute("name");
if (name == null)
continue;
bool isType = name.StartsWith("T:", StringComparison.OrdinalIgnoreCase);
if (isType ||
name.StartsWith("P:", StringComparison.OrdinalIgnoreCase))
{
int lastDot = name.Length;
string typeName;
if (isType)
{
typeName = name.Substring(2); // skip leading "T:"
}
else
{
lastDot = name.LastIndexOf('.');
typeName = name.Substring(2, lastDot - 2);
}
typeName += AssemblyFullName;
Type t = Type.GetType(typeName);
if (t != null && t.IsPublic && t.IsClass &&
foreach (XElement member in xdoc.Descendants("member"))
{
try
{
string name = (string)member.Attribute("name");
if (name == null)
continue;
bool isType = name.StartsWith("T:", StringComparison.OrdinalIgnoreCase);
if (isType ||
name.StartsWith("P:", StringComparison.OrdinalIgnoreCase))
{
int lastDot = name.Length;
string typeName;
if (isType)
{
typeName = name.Substring(2); // skip leading "T:"
}
else
{
lastDot = name.LastIndexOf('.');
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))
{
string desc = ParseDescription(member);
{
string desc = ParseDescription(member);
if (desc == null)
continue;
desc = desc.Trim();
desc = string.Join(" ", desc.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries));
if (isType)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(t);
}
catch { isBrowsable = false; }
if (isBrowsable)
builder.AddCallback(t, b => b.AddCustomAttributes(new DescriptionAttribute(desc)));
else //Hide from intellisense
{
builder.AddCallback(t, b => b.AddCustomAttributes(
new BrowsableAttribute(false),
new Microsoft.Windows.Design.ToolboxBrowsableAttribute(false),
new ToolboxItemAttribute(false)));
}
}
else
{
string propName = name.Substring(lastDot + 1);
PropertyInfo pi = t.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (pi != null)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(pi);
}
catch { isBrowsable = false; }
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)));
}
}
}
}
}
catch (Exception)
{
}
}
}
private static bool IsBrowsable(Type t)
{
var attrs = t.GetCustomAttributes(Types.PlatformTypes.EditorBrowsableAttributeType, false);
foreach (var attr in attrs)
{
desc = desc.Trim();
desc = string.Join(" ", desc.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries));
if (isType)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(t);
}
catch { isBrowsable = false; }
if (isBrowsable)
builder.AddCallback(t, b => b.AddCustomAttributes(new DescriptionAttribute(desc)));
else //Hide from intellisense
{
builder.AddCallback(t, b => b.AddCustomAttributes(
new BrowsableAttribute(false),
new Microsoft.Windows.Design.ToolboxBrowsableAttribute(false),
new ToolboxItemAttribute(false)));
}
}
else
{
string propName = name.Substring(lastDot + 1);
PropertyInfo pi = t.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (pi != null)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(pi);
}
catch { isBrowsable = false; }
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)));
}
}
}
}
}
catch (Exception)
{
}
}
}
private static bool IsBrowsable(Type t)
{
var attrs = t.GetCustomAttributes(Types.PlatformTypes.EditorBrowsableAttributeType, false);
foreach (var attr in attrs)
{
return Types.PlatformTypes.IsBrowsable(attr);
}
return true;
}
}
return true;
}
private static bool IsBrowsable(System.Reflection.PropertyInfo pi)
{
private static bool IsBrowsable(System.Reflection.PropertyInfo pi)
{
var attrs = pi.GetCustomAttributes(Types.PlatformTypes.EditorBrowsableAttributeType, false);
foreach (var attr in attrs)
{
foreach (var attr in attrs)
{
return Types.PlatformTypes.IsBrowsable(attr);
}
return true;
}
}
return true;
}
/// <summary>
/// Create description string from xml doc summary tag.
/// </summary>
/// <param name="member">A single node of the xml doc.</param>
/// <returns>Description string.</returns>
private static string ParseDescription(XElement member)
{
string desc = null;
XElement memberDesc = member.Descendants("summary").FirstOrDefault();
/// <summary>
/// Create description string from xml doc summary tag.
/// </summary>
/// <param name="member">A single node of the xml doc.</param>
/// <returns>Description string.</returns>
private static string ParseDescription(XElement member)
{
string desc = null;
XElement memberDesc = member.Descendants("summary").FirstOrDefault();
if (memberDesc != null)
{
IEnumerable<XNode> nodes = memberDesc.DescendantNodes();
if (memberDesc != null)
{
IEnumerable<XNode> nodes = memberDesc.DescendantNodes();
if (nodes != null)
{
foreach (XNode node in nodes)
{
if (node.NodeType == System.Xml.XmlNodeType.Text)
{
desc += node.ToString();
}
else
{
string s = node.ToString();
int i = s.LastIndexOf('.');
int j = s.LastIndexOf('"');
if (nodes != null)
{
foreach (XNode node in nodes)
{
if (node.NodeType == System.Xml.XmlNodeType.Text)
{
desc += node.ToString();
}
else
{
string s = node.ToString();
int i = s.LastIndexOf('.');
int j = s.LastIndexOf('"');
if ((i != -1 || j != -1) && j - i - 1 > 0)
{
try
{
desc += s.Substring(i + 1, j - i - 1);
}
catch { }
}
}
}
}
}
return desc;
}
if ((i != -1 || j != -1) && j - i - 1 > 0)
{
try
{
desc += s.Substring(i + 1, j - i - 1);
}
catch { }
}
}
}
}
}
return desc;
}
/// <summary>
/// Provide a place to add custom attributes without creating a AttributeTableBuilder subclass.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
protected virtual void AddAttributes(AttributeTableBuilder builder)
{
}
}
/// <summary>
/// Provide a place to add custom attributes without creating a AttributeTableBuilder subclass.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
protected virtual void AddAttributes(AttributeTableBuilder builder)
{
}
}
}

Просмотреть файл

@ -8,43 +8,42 @@ using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.Design.Types
{
internal class PlatformTypes
{
public static readonly Type DependencyObjectType = typeof(DependencyObject);
public static readonly Type UIElementType = typeof(UIElement);
public static readonly Type FrameworkElementType = typeof(FrameworkElement);
public static readonly Type EditorBrowsableAttributeType = typeof(System.ComponentModel.EditorBrowsableAttribute);
internal class PlatformTypes
{
public static readonly Type DependencyObjectType = typeof(DependencyObject);
public static readonly Type UIElementType = typeof(UIElement);
public static readonly Type FrameworkElementType = typeof(FrameworkElement);
public static readonly Type EditorBrowsableAttributeType = typeof(System.ComponentModel.EditorBrowsableAttribute);
/// <summary>
/// Used by MetadataRegistrationBase to get the browsable state
/// </summary>
/// <param name="editorBrowsableAttribute">This parameter must be of type 'System.ComponentModel.EditorBrowsableAttribute'</param>
/// <returns></returns>
public static bool IsBrowsable(object editorBrowsableAttribute)
{
if (editorBrowsableAttribute is System.ComponentModel.EditorBrowsableAttribute)
return (editorBrowsableAttribute as System.ComponentModel.EditorBrowsableAttribute).State !=
System.ComponentModel.EditorBrowsableState.Never;
return true;
}
/// <summary>
/// Used by MetadataRegistrationBase to get the browsable state
/// </summary>
/// <param name="editorBrowsableAttribute">This parameter must be of type 'System.ComponentModel.EditorBrowsableAttribute'</param>
/// <returns></returns>
public static bool IsBrowsable(object editorBrowsableAttribute)
{
if (editorBrowsableAttribute is System.ComponentModel.EditorBrowsableAttribute)
return (editorBrowsableAttribute as System.ComponentModel.EditorBrowsableAttribute).State !=
System.ComponentModel.EditorBrowsableState.Never;
return true;
}
public static class Control
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "Control");
public static readonly PropertyIdentifier BackgroundProperty = new PropertyIdentifier(TypeId, "Background");
public static readonly PropertyIdentifier BorderBrushProperty = new PropertyIdentifier(TypeId, "BorderBrush");
public static readonly PropertyIdentifier BorderThicknessProperty = new PropertyIdentifier(TypeId, "BorderThickness");
}
public static class Control
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "Control");
public static readonly PropertyIdentifier BackgroundProperty = new PropertyIdentifier(TypeId, "Background");
public static readonly PropertyIdentifier BorderBrushProperty = new PropertyIdentifier(TypeId, "BorderBrush");
public static readonly PropertyIdentifier BorderThicknessProperty = new PropertyIdentifier(TypeId, "BorderThickness");
}
public static class FrameworkElement
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "FrameworkElement");
public static readonly PropertyIdentifier MarginProperty = new PropertyIdentifier(TypeId, "Margin");
public static readonly PropertyIdentifier HorizontalAlignmentProperty = new PropertyIdentifier(TypeId, "HorizontalAlignment");
public static readonly PropertyIdentifier VerticalAlignmentProperty = new PropertyIdentifier(TypeId, "VerticalAlignment");
public static readonly PropertyIdentifier HeightProperty = new PropertyIdentifier(TypeId, "Height");
public static readonly PropertyIdentifier WidthProperty = new PropertyIdentifier(TypeId, "Width");
}
}
public static class FrameworkElement
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "FrameworkElement");
public static readonly PropertyIdentifier MarginProperty = new PropertyIdentifier(TypeId, "Margin");
public static readonly PropertyIdentifier HorizontalAlignmentProperty = new PropertyIdentifier(TypeId, "HorizontalAlignment");
public static readonly PropertyIdentifier VerticalAlignmentProperty = new PropertyIdentifier(TypeId, "VerticalAlignment");
public static readonly PropertyIdentifier HeightProperty = new PropertyIdentifier(TypeId, "Height");
public static readonly PropertyIdentifier WidthProperty = new PropertyIdentifier(TypeId, "Width");
}
}
}

Просмотреть файл

@ -96,7 +96,6 @@
<Compile Include="InAppNotificationMetadata.cs" />
<Compile Include="LayoutTransitionControlMetadata.cs" />
<Compile Include="LoadingMetadata.cs" />
<Compile Include="MarkdownTextBlockMetadata.cs" />
<Compile Include="MasterDetailsViewMetadata.cs" />
<Compile Include="MenuItemMetadata.cs" />
<Compile Include="MenuMetadata.cs" />

Просмотреть файл

@ -19,7 +19,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.Design
b =>
{
b.AddCustomAttributes(nameof(TextToolbar.Editor), new CategoryAttribute(Properties.Resources.CategoryCommon));
b.AddCustomAttributes(nameof(TextToolbar.Format), new CategoryAttribute(Properties.Resources.CategoryCommon));
b.AddCustomAttributes(nameof(TextToolbar.Formatter), new CategoryAttribute(Properties.Resources.CategoryCommon));
b.AddCustomAttributes(nameof(TextToolbar.DefaultButtons), new CategoryAttribute(Properties.Resources.CategoryCommon));
b.AddCustomAttributes(nameof(TextToolbar.CustomButtons), new CategoryAttribute(Properties.Resources.CategoryCommon));

Просмотреть файл

@ -0,0 +1,252 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.Windows.Design.Metadata;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
namespace Microsoft.Toolkit.Uwp.Design.Common
{
public class MetadataRegistrationBase
{
private AttributeTable masterMetadataTable;
internal MetadataRegistrationBase() { }
/// <summary>
/// Build design time metadata attribute table.
/// </summary>
/// <returns>Custom attribute table.</returns>
protected virtual AttributeTable BuildAttributeTable()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
AddDescriptions(builder);
AddAttributes(builder);
AddTables(builder, this);
masterMetadataTable = builder.CreateTable();
return masterMetadataTable;
}
/// <summary>
/// Find all AttributeTableBuilder subclasses in the assembly
/// and add their attributes to the assembly attribute table.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail!")]
private void AddTables(AttributeTableBuilder builder, object parent)
{
Debug.Assert(builder != null, "AddTables is called with null parameter!");
Assembly asm = parent.GetType().Assembly;
foreach (Type t in asm.GetTypes())
{
if (t.IsSubclassOf(typeof(AttributeTableBuilder)))
{
try
{
AttributeTableBuilder atb = (AttributeTableBuilder)Activator.CreateInstance(t);
builder.AddTable(atb.CreateTable());
}
catch (Exception)
{
//error loading design assembly
}
}
}
}
/// <summary>
/// Gets or sets the case sensitive resource name of the embedded XML file.
/// </summary>
protected string XmlResourceName { get; set; }
/// <summary>
/// Gets or sets the FullName of the corresponding run time assembly.
/// </summary>
protected string AssemblyFullName { get; set; }
/// <summary>
/// Create description attribute from run time assembly xml file.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Design time dll should not fail.")]
private void AddDescriptions(AttributeTableBuilder builder)
{
Debug.Assert(builder != null, "AddDescriptions is called with null parameter!");
if (string.IsNullOrEmpty(XmlResourceName) ||
string.IsNullOrEmpty(AssemblyFullName))
{
return;
}
XDocument xdoc = null;
try
{
xdoc = XDocument.Load(new StreamReader(
Assembly.GetExecutingAssembly().GetManifestResourceStream(XmlResourceName)));
}
catch { return; }
if (xdoc == null)
{
return;
}
foreach (XElement member in xdoc.Descendants("member"))
{
try
{
string name = (string)member.Attribute("name");
if (name == null)
continue;
bool isType = name.StartsWith("T:", StringComparison.OrdinalIgnoreCase);
if (isType ||
name.StartsWith("P:", StringComparison.OrdinalIgnoreCase))
{
int lastDot = name.Length;
string typeName;
if (isType)
{
typeName = name.Substring(2); // skip leading "T:"
}
else
{
lastDot = name.LastIndexOf('.');
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))
{
string desc = ParseDescription(member);
if (desc == null)
continue;
desc = desc.Trim();
desc = string.Join(" ", desc.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries));
if (isType)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(t);
}
catch { isBrowsable = false; }
if (isBrowsable)
builder.AddCallback(t, b => b.AddCustomAttributes(new DescriptionAttribute(desc)));
else //Hide from intellisense
{
builder.AddCallback(t, b => b.AddCustomAttributes(
new BrowsableAttribute(false),
new Microsoft.Windows.Design.ToolboxBrowsableAttribute(false),
new ToolboxItemAttribute(false)));
}
}
else
{
string propName = name.Substring(lastDot + 1);
PropertyInfo pi = t.GetProperty(propName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (pi != null)
{
bool isBrowsable = true;
try
{
isBrowsable = IsBrowsable(pi);
}
catch { isBrowsable = false; }
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)));
}
}
}
}
}
catch (Exception)
{
}
}
}
private static bool IsBrowsable(Type t)
{
var attrs = t.GetCustomAttributes(Types.PlatformTypes.EditorBrowsableAttributeType, false);
foreach (var attr in attrs)
{
return Types.PlatformTypes.IsBrowsable(attr);
}
return true;
}
private static bool IsBrowsable(System.Reflection.PropertyInfo pi)
{
var attrs = pi.GetCustomAttributes(Types.PlatformTypes.EditorBrowsableAttributeType, false);
foreach (var attr in attrs)
{
return Types.PlatformTypes.IsBrowsable(attr);
}
return true;
}
/// <summary>
/// Create description string from xml doc summary tag.
/// </summary>
/// <param name="member">A single node of the xml doc.</param>
/// <returns>Description string.</returns>
private static string ParseDescription(XElement member)
{
string desc = null;
XElement memberDesc = member.Descendants("summary").FirstOrDefault();
if (memberDesc != null)
{
IEnumerable<XNode> nodes = memberDesc.DescendantNodes();
if (nodes != null)
{
foreach (XNode node in nodes)
{
if (node.NodeType == System.Xml.XmlNodeType.Text)
{
desc += node.ToString();
}
else
{
string s = node.ToString();
int i = s.LastIndexOf('.');
int j = s.LastIndexOf('"');
if ((i != -1 || j != -1) && j - i - 1 > 0)
{
try
{
desc += s.Substring(i + 1, j - i - 1);
}
catch { }
}
}
}
}
}
return desc;
}
/// <summary>
/// Provide a place to add custom attributes without creating a AttributeTableBuilder subclass.
/// </summary>
/// <param name="builder">The assembly attribute table builder.</param>
protected virtual void AddAttributes(AttributeTableBuilder builder)
{
}
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.Windows.Design.Metadata;
using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.Design.Types
{
internal class PlatformTypes
{
public static readonly Type DependencyObjectType = typeof(DependencyObject);
public static readonly Type UIElementType = typeof(UIElement);
public static readonly Type FrameworkElementType = typeof(FrameworkElement);
public static readonly Type EditorBrowsableAttributeType = typeof(System.ComponentModel.EditorBrowsableAttribute);
/// <summary>
/// Used by MetadataRegistrationBase to get the browsable state
/// </summary>
/// <param name="editorBrowsableAttribute">This parameter must be of type 'System.ComponentModel.EditorBrowsableAttribute'</param>
/// <returns></returns>
public static bool IsBrowsable(object editorBrowsableAttribute)
{
if (editorBrowsableAttribute is System.ComponentModel.EditorBrowsableAttribute)
return (editorBrowsableAttribute as System.ComponentModel.EditorBrowsableAttribute).State !=
System.ComponentModel.EditorBrowsableState.Never;
return true;
}
public static class Control
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "Control");
public static readonly PropertyIdentifier BackgroundProperty = new PropertyIdentifier(TypeId, "Background");
public static readonly PropertyIdentifier BorderBrushProperty = new PropertyIdentifier(TypeId, "BorderBrush");
public static readonly PropertyIdentifier BorderThicknessProperty = new PropertyIdentifier(TypeId, "BorderThickness");
}
public static class FrameworkElement
{
public static readonly TypeIdentifier TypeId = new TypeIdentifier("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "FrameworkElement");
public static readonly PropertyIdentifier MarginProperty = new PropertyIdentifier(TypeId, "Margin");
public static readonly PropertyIdentifier HorizontalAlignmentProperty = new PropertyIdentifier(TypeId, "HorizontalAlignment");
public static readonly PropertyIdentifier VerticalAlignmentProperty = new PropertyIdentifier(TypeId, "VerticalAlignment");
public static readonly PropertyIdentifier HeightProperty = new PropertyIdentifier(TypeId, "Height");
public static readonly PropertyIdentifier WidthProperty = new PropertyIdentifier(TypeId, "Width");
}
}
}

Просмотреть файл

@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
[assembly: SuppressMessage("General", "SWC1001:XmlDocumentationCommentShouldBeSpelledCorrectly", MessageId = "Theming", Justification = "Correct spelling")]
namespace Microsoft.Toolkit.Uwp.UI.Controls.Design.Common
{
/// <summary>
/// Names for ToolboxCategoryAttribute.
/// </summary>
internal static class ToolboxCategoryPaths
{
/// <summary>
/// Basic Controls category.
/// </summary>
public const string Toolkit = "Windows Community Toolkit";
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Reflection;
using Microsoft.Windows.Design.Metadata;
using Microsoft.Toolkit.Uwp.Design.Common;
[assembly: ProvideMetadata(typeof(Microsoft.Toolkit.Uwp.UI.Controls.Design.MetadataRegistration))]
namespace Microsoft.Toolkit.Uwp.UI.Controls.Design
{
public class MetadataRegistration : MetadataRegistrationBase, IProvideAttributeTable
{
public MetadataRegistration() : base()
{
// Note:
// The default constructor sets value of AssemblyFullName and
// XmlResourceName used by MetadataRegistrationBase.AddDescriptions().
// The convention here is that the <RootNamespace> in .design.csproj
// (or Default namespace in Project -> Properties -> Application tab)
// must be the same as runtime assembly's main namespace (t.Namespace)
// plus .Design.
Type t = typeof(Microsoft.Toolkit.Uwp.UI.Controls.MarkdownTextBlock);
AssemblyName an = t.Assembly.GetName();
AssemblyFullName = ", " + an.FullName;
XmlResourceName = t.Namespace + ".Design." + an.Name + ".xml";
}
#region IProvideAttributeTable Members
/// <summary>
/// Gets the AttributeTable for design time metadata.
/// </summary>
public AttributeTable AttributeTable
{
get
{
return BuildAttributeTable();
}
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{67FE47A0-CA93-4680-B770-A0A48C1DBC40}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Design</RootNamespace>
<AssemblyName>Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Design</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NoWarn>$(NoWarn);0618</NoWarn>
<AssetTargetFallback>$(AssetTargetFallback);uap10.0.16299</AssetTargetFallback>
</PropertyGroup>
<PropertyGroup>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\Microsoft.Toolkit.Uwp.UI.Controls.Markdown\bin\Debug\uap10.0.16299\Design\</OutputPath>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>..\Microsoft.Toolkit.Uwp.UI.Controls.Markdown\bin\Release\uap10.0.16299\Design\</OutputPath>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<ValidateFrameworkCompatibility>false</ValidateFrameworkCompatibility>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Runtime.WindowsRuntime" />
<Reference Include="System.Runtime.InteropServices.WindowsRuntime" />
<Reference Include="Microsoft.Windows.Design.Extensibility">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Windows.Design.Interaction">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls.Markdown\Microsoft.Toolkit.Uwp.UI.Controls.Markdown.csproj" Condition="'$(ExcludeRestorePackageImports)' != 'true'">
<Project>{e9faabfb-d726-42c1-83c1-cb46a29fea81}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.Markdown</Name>
<Private>False</Private>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemGroup>
<ItemGroup Label="WinRT References">
<Reference Include="System.Xaml" />
<Reference Include="System.Runtime.WindowsRuntime.UI.Xaml" />
<Reference Include="Windows.Foundation.FoundationContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MarkdownTextBlockMetadata.cs" />
<Compile Include="MetadataRegistration.cs" />
<Compile Include="Common\MetadataRegistrationBase.cs" />
<Compile Include="Common\PlatformTypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Common\ToolboxCategoryPaths.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\Microsoft.Toolkit.Uwp.UI.Controls.Markdown\bin\$(Configuration)\uap10.0.16299\Microsoft.Toolkit.Uwp.UI.Controls.Markdown.xml">
<Link>Microsoft.Toolkit.Uwp.UI.Controls.Markdown.xml</Link>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Pack">
<!-- No-op to avoid build error when packing solution from commandline -->
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Windows Community Toolkit Controls (Design)")]
[assembly: AssemblyDescription("Design time support for Windows Community Toolkit Controls")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Windows Community Toolkit")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]

Просмотреть файл

@ -0,0 +1,180 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.Toolkit.Uwp.UI.Controls.Design.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Toolkit.Uwp.UI.Controls.Design.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Appearance.
/// </summary>
internal static string CategoryAppearance {
get {
return ResourceManager.GetString("CategoryAppearance", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Brush.
/// </summary>
internal static string CategoryBrush {
get {
return ResourceManager.GetString("CategoryBrush", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Common.
/// </summary>
internal static string CategoryCommon {
get {
return ResourceManager.GetString("CategoryCommon", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Drop Shadow.
/// </summary>
internal static string CategoryDropShadow {
get {
return ResourceManager.GetString("CategoryDropShadow", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Interactions.
/// </summary>
internal static string CategoryInteractions {
get {
return ResourceManager.GetString("CategoryInteractions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Layout.
/// </summary>
internal static string CategoryLayout {
get {
return ResourceManager.GetString("CategoryLayout", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style - Code.
/// </summary>
internal static string CategoryMarkdownCodeStyle {
get {
return ResourceManager.GetString("CategoryMarkdownCodeStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style - Header {0}.
/// </summary>
internal static string CategoryMarkdownHeaderStyle {
get {
return ResourceManager.GetString("CategoryMarkdownHeaderStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style - List.
/// </summary>
internal static string CategoryMarkdownListStyle {
get {
return ResourceManager.GetString("CategoryMarkdownListStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style - Quote.
/// </summary>
internal static string CategoryMarkdownQuoteStyle {
get {
return ResourceManager.GetString("CategoryMarkdownQuoteStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style.
/// </summary>
internal static string CategoryMarkdownStyle {
get {
return ResourceManager.GetString("CategoryMarkdownStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Markdown Style - Table.
/// </summary>
internal static string CategoryMarkdownTableStyle {
get {
return ResourceManager.GetString("CategoryMarkdownTableStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text.
/// </summary>
internal static string CategoryText {
get {
return ResourceManager.GetString("CategoryText", resourceCulture);
}
}
}
}

Просмотреть файл

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CategoryAppearance" xml:space="preserve">
<value>Appearance</value>
</data>
<data name="CategoryBrush" xml:space="preserve">
<value>Brush</value>
</data>
<data name="CategoryCommon" xml:space="preserve">
<value>Common</value>
</data>
<data name="CategoryDropShadow" xml:space="preserve">
<value>Drop Shadow</value>
</data>
<data name="CategoryInteractions" xml:space="preserve">
<value>Interactions</value>
</data>
<data name="CategoryLayout" xml:space="preserve">
<value>Layout</value>
</data>
<data name="CategoryMarkdownCodeStyle" xml:space="preserve">
<value>Markdown Style - Code</value>
</data>
<data name="CategoryMarkdownHeaderStyle" xml:space="preserve">
<value>Markdown Style - Header {0}</value>
</data>
<data name="CategoryMarkdownListStyle" xml:space="preserve">
<value>Markdown Style - List</value>
</data>
<data name="CategoryMarkdownQuoteStyle" xml:space="preserve">
<value>Markdown Style - Quote</value>
</data>
<data name="CategoryMarkdownStyle" xml:space="preserve">
<value>Markdown Style</value>
</data>
<data name="CategoryMarkdownTableStyle" xml:space="preserve">
<value>Markdown Style - Table</value>
</data>
<data name="CategoryText" xml:space="preserve">
<value>Text</value>
</data>
</root>

Просмотреть файл

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.Toolkit.Uwp.UI.Controls.Design.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

Просмотреть файл

@ -0,0 +1,49 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFramework>uap10.0.16299</TargetFramework>
<Title>Windows Community Toolkit Controls Markdown</Title>
<Description>
This library provides a XAML MarkdownTextBlock control, an efficient and extensible control that can parse and render markdown. It is part of the Windows Community Toolkit.
</Description>
<PackageTags>UWP Toolkit Windows Controls XAML Markdown MarkdownTextBlock</PackageTags>
<RootNamespace>Microsoft.Toolkit.Uwp.UI.Controls</RootNamespace>
<!-- ARM64 builds for managed apps use .NET Native. We can't use the Reflection Provider for that. -->
<EnableTypeInfoReflection Condition="'$(Configuration)' == 'Debug'">false</EnableTypeInfoReflection>
</PropertyGroup>
<ItemGroup>
<None Include="VisualStudioToolsManifest.xml" />
<None Include="$(OutDir)\Design\$(MSBuildProjectName).Design.dll;$(OutDir)\Design\$(MSBuildProjectName).Design.pdb" Pack="true" PackagePath="lib\$(TargetFramework)\Design" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ColorCode.UWP" Version="2.0.6" />
<ProjectReference Include="..\Microsoft.Toolkit.Parsers\Microsoft.Toolkit.Parsers.csproj" />
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls\Microsoft.Toolkit.Uwp.UI.Controls.csproj" />
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI\Microsoft.Toolkit.Uwp.UI.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
<ItemGroup>
<GeneratedCSFiles Include="**\*.g.cs;**\*.g.i.cs" />
</ItemGroup>
<Message Text="CSFiles: @(GeneratedCSFiles->'&quot;%(Identity)&quot;')" />
<Exec Command="for %%f in (@(GeneratedCSFiles->'&quot;%(Identity)&quot;')) do echo #pragma warning disable &gt; %%f.temp &amp;&amp; type %%f &gt;&gt; %%f.temp &amp;&amp; move /y %%f.temp %%f &gt; NUL" />
</Target>
</Project>

Просмотреть файл

@ -20,13 +20,15 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown
/// </summary>
public class MarkDownFormatter : Formatter
{
/// <summary>
/// Initializes a new instance of the <see cref="MarkDownFormatter"/> class.
/// </summary>
/// <param name="model"><see cref="TextToolbar"/> where formatter will be used</param>
public MarkDownFormatter(TextToolbar model)
: base(model)
internal const string QuoteElement = "Quote";
internal const string HeadersElement = "Headers";
internal const string CodeElement = "Code";
/// <inheritdoc/>
public override void SetModel(TextToolbar model)
{
base.SetModel(model);
CommonButtons = new CommonButtons(model);
ButtonActions = new MarkDownButtonActions(this);
}
@ -40,7 +42,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown
var list = new ListBox { Margin = new Thickness(0), Padding = new Thickness(0) };
headerFlyout = new Flyout { Content = list };
if (ControlHelpers.IsXamlRootAvailable && button.XamlRoot != null)
if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "XamlRoot") && button.XamlRoot != null)
{
headerFlyout.XamlRoot = button.XamlRoot;
}
@ -438,7 +440,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown
return ListLineIterator + ". ";
}
private CommonButtons CommonButtons { get; }
private CommonButtons CommonButtons { get; set; }
/// <inheritdoc/>
public override string Text
@ -459,7 +461,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown
OrderedListButton = OrderedListButton ?? CommonButtons.OrderedList;
QuoteButton = new ToolbarButton
{
Name = TextToolbar.QuoteElement,
Name = QuoteElement,
ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_QuoteLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Icon = new SymbolIcon { Symbol = Symbol.Message },
Activation = FormatQuote
@ -475,14 +477,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown
new ToolbarButton
{
Name = TextToolbar.HeadersElement,
Name = HeadersElement,
Icon = new SymbolIcon { Symbol = Symbol.FontSize },
ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_HeaderLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Activation = StyleHeader
},
new ToolbarButton
{
Name = TextToolbar.CodeElement,
Name = CodeElement,
ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_CodeLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Icon = new FontIcon { Glyph = "{}", FontFamily = new FontFamily("Segoe UI"), Margin = new Thickness(0, -5, 0, 0) },
Activation = FormatCode

Просмотреть файл

@ -0,0 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Markdown/MarkdownTextBlock/MarkdownTextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Просмотреть файл

@ -0,0 +1,7 @@
<FileList>
<File Reference="Microsoft.Toolkit.Uwp.UI.Controls.MarkdownTextBlock.dll">
<ToolboxItems VSCategory="Windows Community Toolkit" BlendCategory="Windows Community Toolkit">
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.MarkdownTextBlock" />
</ToolboxItems>
</File>
</FileList>

Просмотреть файл

@ -43,6 +43,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
Dismiss(InAppNotificationDismissKind.Timeout);
}
private void OnCurrentStateChanging(object sender, VisualStateChangedEventArgs e)
{
if (e.NewState.Name == StateContentVisible)
{
Visibility = Visibility.Visible;
}
}
private void OnCurrentStateChanged(object sender, VisualStateChangedEventArgs e)
{
switch (e.NewState.Name)

Просмотреть файл

@ -51,6 +51,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
if (_visualStateGroup != null)
{
_visualStateGroup.CurrentStateChanging -= OnCurrentStateChanging;
_visualStateGroup.CurrentStateChanged -= OnCurrentStateChanged;
}
@ -67,6 +68,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
if (_visualStateGroup != null)
{
_visualStateGroup.CurrentStateChanging += OnCurrentStateChanging;
_visualStateGroup.CurrentStateChanged += OnCurrentStateChanged;
}

Просмотреть файл

@ -1,7 +0,0 @@
This project began as an independent open source project called Universal Markdown. It was originally created by Quinn Damerell
and Paul Bartrum for use in Baconit, an open source reddit UWP app.
The goal of this project was to make a universal markdown renderer control that's easy to use but is also very efficient. This
control is intended to be used in virtualized lists, so the performance needs to be great. Thanks to a lot of hard work from Paul,
the control supports the full markdown syntax and is very performant.

Просмотреть файл

@ -23,7 +23,6 @@
- InfiniteCanvas: Supports Infinite Scrolling, Ink, Text, Format Text, Zoom in/out, Redo, Undo, Export &amp; Import.
- LayoutTransformControl: Support for transformations as if applied by LayoutTransform.
- Loading: Helps to show content with animation to the user while the app is doing some calculation.
- MarkdownTextBlock: An efficient and extensible control that can parse and render markdown.
- MasterDetailsView: Implements the Master/Details design pattern.
- OrbitView: Positions items in a circle around a center element and supports orbits and anchors.
- RadialGauge: Displays a value within a range, using a needle on a circular face.
@ -45,11 +44,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ColorCode.UWP" Version="2.0.6" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Animations\Microsoft.Toolkit.Uwp.UI.Animations.csproj" />
<ProjectReference Include="..\Microsoft.Toolkit.Uwp\Microsoft.Toolkit.Uwp.csproj" />
<ProjectReference Include="..\Microsoft.Toolkit.Parsers\Microsoft.Toolkit.Parsers.csproj" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,27 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats
{
/// <summary>
/// Identifies the Format to be used by <see cref="TextToolbar"/>
/// </summary>
public enum Format
{
/// <summary>
/// Utilizes the Built-In RichText Formatter
/// </summary>
RichText,
/// <summary>
/// Utilizes the Built-In Markdown Formatter
/// </summary>
MarkDown,
/// <summary>
/// Utilizes the provided Custom Formatter using the Formatter Property
/// </summary>
Custom
}
}

Просмотреть файл

@ -13,16 +13,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats
/// </summary>
public abstract class Formatter
{
/// <summary>
/// Initializes a new instance of the <see cref="Formatter"/> class.
/// </summary>
/// <param name="model">The <see cref="TextToolbar"/>where Formatter is used</param>
public Formatter(TextToolbar model)
{
Model = model;
Model.EditorChanged += Model_EditorChanged;
}
/// <summary>
/// Called when text editor has changed
/// </summary>
@ -155,7 +145,31 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats
/// <summary>
/// Gets the source Toolbar
/// </summary>
public TextToolbar Model { get; }
public TextToolbar Model { get; private set; }
/// <summary>
/// This method is called to unset event handlers that might have been registers by <see cref="SetModel(TextToolbar)"/>
/// </summary>
/// <param name="model">The old <see cref="TextToolbar"/> the Formatter was associated with</param>
public virtual void UnsetModel(TextToolbar model)
{
model.EditorChanged -= Model_EditorChanged;
}
/// <summary>
/// Sets the <see cref="TextToolbar"/> where the Formatter is used
/// </summary>
/// <param name="model">The <see cref="TextToolbar"/> where Formatter is used</param>
public virtual void SetModel(TextToolbar model)
{
if (Model != null)
{
Model.EditorChanged -= Model_EditorChanged;
}
Model = model;
Model.EditorChanged += Model_EditorChanged;
}
/// <summary>
/// Gets or sets a map of the Actions taken when a button is pressed. Required for Common Button actions (Unless you override both Activation and ShiftActivation)

Просмотреть файл

@ -16,13 +16,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText
/// </summary>
public class RichTextFormatter : Formatter
{
/// <summary>
/// Initializes a new instance of the <see cref="RichTextFormatter"/> class.
/// </summary>
/// <param name="model">The <see cref="TextToolbar"/></param>
public RichTextFormatter(TextToolbar model)
: base(model)
/// <inheritdoc/>
public override void SetModel(TextToolbar model)
{
base.SetModel(model);
CommonButtons = new CommonButtons(model);
ButtonActions = new RichTextButtonActions(this);
}
@ -88,7 +86,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText
base.OnSelectionChanged();
}
private CommonButtons CommonButtons { get; }
private CommonButtons CommonButtons { get; set; }
/// <inheritdoc/>
public override string Text

Просмотреть файл

@ -6,6 +6,7 @@ using System;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
@ -31,8 +32,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
return;
}
var bar = obj as TextToolbar;
if (bar != null)
if (obj is TextToolbar bar)
{
var oldEditor = args.OldValue as RichEditBox;
var newEditor = args.NewValue as RichEditBox;
@ -45,7 +45,15 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
if (newEditor != null)
{
newEditor.AddHandler(KeyDownEvent, bar.KeyEventHandler, handledEventsToo: true);
bar.CreateFormatter();
if (bar.Formatter != null)
{
bar.Formatter.SetModel(bar);
bar.DefaultButtons = bar.Formatter.DefaultButtons;
}
else
{
bar.DefaultButtons = null;
}
}
var editorArgs = new EditorChangedArgs
@ -58,20 +66,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
}
}
/// <summary>
/// Creates a new formatter, if it is a built-in formatter.
/// </summary>
/// <param name="obj">TextToolbar</param>
/// <param name="args">Property Changed Args</param>
private static void OnFormatTypeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var bar = obj as TextToolbar;
if (bar != null)
{
bar.CreateFormatter();
}
}
/// <summary>
/// Rebuilds the Toolbar if the formatter changes during operation
/// </summary>
@ -79,11 +73,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <param name="args">Property Changed Args</param>
private static void OnFormatterChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var bar = obj as TextToolbar;
if (bar != null && bar.Formatter != null)
if (obj is TextToolbar bar)
{
bar.DefaultButtons = bar.Formatter.DefaultButtons;
bar.BuildBar();
if (args.OldValue is Formatter formatter)
{
formatter.UnsetModel(bar);
}
if (bar.Formatter != null)
{
bar.Formatter.SetModel(bar);
bar.DefaultButtons = bar.Formatter.DefaultButtons;
bar.BuildBar();
}
}
}
@ -94,14 +96,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <param name="args">Property Changed Args</param>
private static void OnButtonMapChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var bar = obj as TextToolbar;
if (bar != null)
if (obj is TextToolbar bar)
{
var oldSource = args.OldValue as ButtonMap;
var newSource = args.NewValue as ButtonMap;
var root = bar.GetTemplateChild(RootControl) as CommandBar;
if (oldSource != null)
if (args.OldValue is ButtonMap oldSource)
{
oldSource.CollectionChanged -= bar.OnButtonMapModified;
@ -114,7 +113,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
}
}
if (newSource != null)
if (args.NewValue is ButtonMap newSource)
{
newSource.CollectionChanged += bar.OnButtonMapModified;
@ -133,19 +132,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <param name="args">Property Changed Args</param>
private static void OnDefaultButtonModificationsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var bar = obj as TextToolbar;
if (bar != null)
if (obj is TextToolbar bar)
{
var oldSource = args.OldValue as DefaultButtonModificationList;
var newSource = args.NewValue as DefaultButtonModificationList;
var root = bar.GetTemplateChild(RootControl) as CommandBar;
if (oldSource != null)
if (args.OldValue is DefaultButtonModificationList oldSource)
{
oldSource.CollectionChanged -= bar.OnDefaultButtonModificationListChanged;
}
if (newSource != null)
if (args.NewValue is DefaultButtonModificationList newSource)
{
newSource.CollectionChanged += bar.OnDefaultButtonModificationListChanged;
@ -165,8 +161,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <param name="e">Collection Changed Args</param>
private void OnButtonMapModified(object sender, NotifyCollectionChangedEventArgs e)
{
var root = GetTemplateChild(RootControl) as CommandBar;
if (root != null)
if (GetTemplateChild(RootControl) is CommandBar root)
{
switch (e.Action)
{
@ -175,8 +170,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
{
AddToolbarItem(item, root);
var button = item as ToolbarButton;
if (button != null)
if (item is ToolbarButton button)
{
button.PropertyChanged += ToolbarItemPropertyChanged;
}
@ -189,8 +183,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
{
RemoveToolbarItem(item);
var button = item as ToolbarButton;
if (button != null)
if (item is ToolbarButton button)
{
button.PropertyChanged -= ToolbarItemPropertyChanged;
}
@ -232,8 +225,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <param name="e">Property Changed Event</param>
private void ToolbarItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var root = GetTemplateChild(RootControl) as CommandBar;
if (root != null)
if (GetTemplateChild(RootControl) is CommandBar root)
{
if (e.PropertyName == nameof(IToolbarItem.Position))
{
@ -256,8 +248,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
LastKeyPress = e.Key;
var root = GetTemplateChild(RootControl) as CommandBar;
if (root != null)
if (GetTemplateChild(RootControl) is CommandBar root)
{
if (ControlKeyDown && e.Key != VirtualKey.Control)
{
@ -322,4 +313,4 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// </summary>
public event EventHandler<EditorChangedArgs> EditorChanged;
}
}
}

Просмотреть файл

@ -4,8 +4,6 @@
using System.Linq;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.MarkDown;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
@ -25,8 +23,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// <returns>Default Toolbar Button</returns>
public ToolbarButton GetDefaultButton(ButtonType button)
{
var root = GetTemplateChild(RootControl) as CommandBar;
if (root != null)
if (GetTemplateChild(RootControl) is CommandBar root)
{
var element = root.PrimaryCommands.OfType<ToolbarButton>().FirstOrDefault(item => ((FrameworkElement)item).Name == button.ToString());
return element;
@ -35,30 +32,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
return null;
}
/// <summary>
/// Creates one of the Default formatters.
/// </summary>
private void CreateFormatter()
{
switch (Format)
{
case TextToolbarFormats.Format.MarkDown:
Formatter = new MarkDownFormatter(this);
break;
case TextToolbarFormats.Format.RichText:
Formatter = new RichTextFormatter(this);
break;
}
}
/// <summary>
/// Attaches all of the Default Buttons, Removing any that are to be removed, and inserting Custom buttons.
/// </summary>
private void BuildBar()
{
var root = GetTemplateChild(RootControl) as CommandBar;
if (root != null)
if (GetTemplateChild(RootControl) is CommandBar root)
{
root.PrimaryCommands.Clear();
@ -109,8 +88,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
if (!root.PrimaryCommands.Contains(item))
{
var button = item as ToolbarButton;
if (button != null)
if (item is ToolbarButton button)
{
button.Model = this;
}

Просмотреть файл

@ -4,6 +4,7 @@
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@ -21,17 +22,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
public static readonly DependencyProperty EditorProperty =
DependencyProperty.Register(nameof(Editor), typeof(RichEditBox), typeof(TextToolbar), new PropertyMetadata(null, OnEditorChanged));
/// <summary>
/// Identifies the <see cref="Format"/> dependency property.
/// </summary>
public static readonly DependencyProperty FormatProperty =
DependencyProperty.Register(nameof(Format), typeof(Format), typeof(TextToolbar), new PropertyMetadata(Format.RichText, OnFormatTypeChanged));
/// <summary>
/// Identifies the <see cref="Formatter"/> dependency property.
/// </summary>
public static readonly DependencyProperty FormatterProperty =
DependencyProperty.Register(nameof(Formatter), typeof(Formatter), typeof(TextToolbar), new PropertyMetadata(null, OnFormatterChanged));
DependencyProperty.Register(nameof(Formatter), typeof(Formatter), typeof(TextToolbar), new PropertyMetadata(new RichTextFormatter(), OnFormatterChanged));
/// <summary>
/// Identifies the <see cref="DefaultButton"/> dependency property.
@ -66,15 +61,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
set { SetValue(EditorProperty, value); }
}
/// <summary>
/// Gets or sets which formatter to use, and which buttons to provide.
/// </summary>
public Format Format
{
get { return (Format)GetValue(FormatProperty); }
set { SetValue(FormatProperty, value); }
}
/// <summary>
/// Gets or sets the formatter instance which is used to format the text, using the buttons and shortcuts.
/// </summary>

Просмотреть файл

@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons.Common;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
@ -20,12 +20,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
internal const string BoldElement = "Bold";
internal const string ItalicsElement = "Italics";
internal const string StrikethoughElement = "Strikethrough";
internal const string CodeElement = "Code";
internal const string QuoteElement = "Quote";
internal const string LinkElement = "Link";
internal const string ListElement = "List";
internal const string OrderedElement = "OrderedList";
internal const string HeadersElement = "Headers";
/// <summary>
/// Initializes a new instance of the <see cref="TextToolbar"/> class.
@ -48,7 +45,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
{
if (Formatter == null)
{
CreateFormatter();
throw new InvalidOperationException("No formatter specified.");
}
else
{
@ -58,4 +55,4 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
base.OnApplyTemplate();
}
}
}
}

Просмотреть файл

@ -1,48 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats;
using Windows.UI.Xaml.Data;
namespace Microsoft.Toolkit.Uwp.UI.Converters
{
/// <summary>
/// Compares if Formats are equal and returns bool
/// </summary>
public class ToolbarFormatActiveConverter : IValueConverter
{
/// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is Format)
{
CurrentFormat = (Format)value;
return CurrentFormat == Format;
}
else
{
return value;
}
}
/// <inheritdoc/>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (CurrentFormat != null)
{
return CurrentFormat;
}
return value;
}
/// <summary>
/// Gets or sets the <see cref="Format"/> to compare
/// </summary>
public Format Format { get; set; }
private Format? CurrentFormat { get; set; }
}
}

Просмотреть файл

@ -16,7 +16,6 @@
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/InfiniteCanvas.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/LayoutTransformControl/LayoutTransformControl.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Loading/Loading.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/MarkdownTextBlock.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/MasterDetailsView/MasterDetailsView.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Menu/Menu.xaml" />
<ResourceDictionary Source="ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.xaml" />

Просмотреть файл

@ -19,7 +19,6 @@
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.InfiniteCanvas" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.LayoutTransformControl" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.Loading" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.MarkdownTextBlock" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.MasterDetailsView" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.Menu" />
<Item Type="Microsoft.Toolkit.Uwp.UI.Controls.MenuItem" />

Просмотреть файл

@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.UI.Behaviors
{
/// <summary>
/// This behavior automatically sets the focus on the associated <see cref="Control"/> when it is loaded.
/// </summary>
public sealed class AutoFocusBehavior : BehaviorBase<Control>
{
/// <inheritdoc/>
protected override void OnAssociatedObjectLoaded() => AssociatedObject.Focus(FocusState.Programmatic);
}
}

Просмотреть файл

@ -0,0 +1,192 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Behaviors
{
#pragma warning disable SA1402 // File may only contain a single type
/// <summary>
/// This behavior sets the focus on the first control of <see cref="Targets"/> which accepts it.
/// The focus will be set following the <see cref="Targets"/> order. The first control being ready
/// and accepting the focus will receive it.
/// The focus can be set to another control with a higher priority if it loads before <see cref="FocusEngagementTimeout"/>.
/// </summary>
[ContentProperty(Name = nameof(Targets))]
public sealed class FocusBehavior : BehaviorBase<UIElement>
{
/// <summary>
/// The DP to store the <see cref="Targets"/> property value.
/// </summary>
public static readonly DependencyProperty TargetsProperty = DependencyProperty.Register(
nameof(Targets),
typeof(FocusTargetList),
typeof(FocusBehavior),
new PropertyMetadata(null, OnTargetsPropertyChanged));
/// <summary>
/// The DP to store the <see cref="FocusEngagementTimeout"/> property value.
/// </summary>
public static readonly DependencyProperty FocusEngagementTimeoutProperty = DependencyProperty.Register(
nameof(FocusEngagementTimeout),
typeof(TimeSpan),
typeof(FocusBehavior),
new PropertyMetadata(TimeSpan.FromMilliseconds(100)));
private DispatcherTimer _timer;
/// <summary>
/// Initializes a new instance of the <see cref="FocusBehavior"/> class.
/// </summary>
public FocusBehavior() => Targets = new FocusTargetList();
/// <summary>
/// Gets or sets the ordered list of controls which should receive the focus when the associated object is loaded.
/// </summary>
public FocusTargetList Targets
{
get => (FocusTargetList)GetValue(TargetsProperty);
set => SetValue(TargetsProperty, value);
}
/// <summary>
/// Gets or sets the timeout before the <see cref="FocusBehavior"/> stops trying to set the focus to a control with
/// a higher priority.
/// </summary>
public TimeSpan FocusEngagementTimeout
{
get => (TimeSpan)GetValue(FocusEngagementTimeoutProperty);
set => SetValue(FocusEngagementTimeoutProperty, value);
}
/// <inheritdoc/>
protected override void OnAssociatedObjectLoaded() => ApplyFocus();
/// <inheritdoc/>
protected override void OnDetaching() => Stop();
private static void OnTargetsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var behavior = (FocusBehavior)d;
if (e.OldValue is FocusTargetList oldTargets)
{
behavior.Stop(oldTargets);
}
behavior.ApplyFocus();
}
private void ApplyFocus()
{
if (Targets.Count == 0)
{
return;
}
var focusedControlIndex = -1;
for (var i = 0; i < Targets.Count; i++)
{
var control = Targets[i].Control;
if (control.IsLoaded)
{
if (control.Focus(FocusState.Programmatic))
{
focusedControlIndex = i;
break;
}
}
else
{
control.Loaded += OnControlLoaded;
}
}
if (focusedControlIndex == 0 || Targets.All(t => t.Control?.IsLoaded == true))
{
// The first control has received the focus or all the control are loaded and none can take the focus: we stop.
Stop();
}
else if (focusedControlIndex > 0)
{
// We have been able to set the focus on one control.
// We start the timer to detect if we can focus another control with an higher priority.
// This allows us to handle the case where the controls are not loaded in the order we expect.
if (_timer is null)
{
_timer = new DispatcherTimer
{
Interval = FocusEngagementTimeout,
};
_timer.Tick += OnEngagementTimerTick;
_timer.Start();
}
}
}
private void OnEngagementTimerTick(object sender, object e)
{
ApplyFocus();
Stop();
}
private void OnControlLoaded(object sender, RoutedEventArgs e) => ApplyFocus();
private void Stop(FocusTargetList targets = null)
{
if (_timer != null)
{
_timer.Stop();
_timer = null;
}
foreach (var target in targets ?? Targets)
{
if (target.Control is null)
{
continue;
}
target.Control.Loaded -= OnControlLoaded;
}
}
}
/// <summary>
/// A collection of <see cref="FocusTarget"/>.
/// </summary>
public sealed class FocusTargetList : List<FocusTarget>
{
}
/// <summary>
/// A target for the <see cref="FocusBehavior"/>.
/// </summary>
public sealed class FocusTarget : DependencyObject
{
/// <summary>
/// The DP to store the <see cref="Control"/> property value.
/// </summary>
public static readonly DependencyProperty ControlProperty = DependencyProperty.Register(
nameof(Control),
typeof(Control),
typeof(FocusTarget),
new PropertyMetadata(null));
/// <summary>
/// Gets or sets the control that will receive the focus.
/// </summary>
public Control Control
{
get => (Control)GetValue(ControlProperty);
set => SetValue(ControlProperty, value);
}
}
#pragma warning restore SA1402 // File may only contain a single type
}

Просмотреть файл

@ -0,0 +1,95 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace Microsoft.Toolkit.Uwp.UI.Converters
{
/// <summary>
/// This class returns an object or another, depending on whether the type of the provided value matches another provided Type.
/// </summary>
public class TypeToObjectConverter : DependencyObject, IValueConverter
{
/// <summary>
/// Identifies the <see cref="TrueValue"/> property.
/// </summary>
public static readonly DependencyProperty TrueValueProperty =
DependencyProperty.Register(nameof(TrueValue), typeof(object), typeof(TypeToObjectConverter), new PropertyMetadata(null));
/// <summary>
/// Identifies the <see cref="FalseValue"/> property.
/// </summary>
public static readonly DependencyProperty FalseValueProperty =
DependencyProperty.Register(nameof(FalseValue), typeof(object), typeof(TypeToObjectConverter), new PropertyMetadata(null));
/// <summary>
/// Identifies the <see cref="Type"/> property.
/// </summary>
public static readonly DependencyProperty TypeProperty =
DependencyProperty.Register(nameof(Type), typeof(Type), typeof(TypeToObjectConverter), new PropertyMetadata(typeof(object)));
/// <summary>
/// Gets or sets the value to be returned when the type of the provided value matches <see cref="Type"/>.
/// </summary>
public object TrueValue
{
get { return GetValue(TrueValueProperty); }
set { SetValue(TrueValueProperty, value); }
}
/// <summary>
/// Gets or sets the value to be returned when the type of the provided value does not match <see cref="Type"/>.
/// </summary>
public object FalseValue
{
get { return GetValue(FalseValueProperty); }
set { SetValue(FalseValueProperty, value); }
}
/// <summary>
/// Gets or sets the Type used to compare the type of the provided value.
/// </summary>
public Type Type
{
get { return (Type)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
/// <summary>
/// Convert the <paramref name="value"/>'s Type to an other object.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">An optional parameter to be used to invert the converter logic.</param>
/// <param name="language">The language of the conversion.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, string language)
{
var typeMatches = value != null && Type.Equals(value.GetType());
// Negate if needed
if (ConverterTools.TryParseBool(parameter))
{
typeMatches = !typeMatches;
}
return ConverterTools.Convert(typeMatches ? TrueValue : FalseValue, targetType);
}
/// <summary>
/// Not implemented.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">Optional parameter. Not used.</param>
/// <param name="language">The language of the conversion. Not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,852 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
#if !NETSTANDARD1_4
using System.Runtime.InteropServices;
#endif
using System.Threading;
#nullable enable
namespace Microsoft.Toolkit.Diagnostics
{
/// <summary>
/// Helper methods to efficiently throw exceptions.
/// </summary>
public static partial class ThrowHelper
{
/// <summary>
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArrayTypeMismatchException<T>(string message)
{
throw new ArrayTypeMismatchException(message);
}
/// <summary>
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ArrayTypeMismatchException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArrayTypeMismatchException<T>(string message, Exception innerException)
{
throw new ArrayTypeMismatchException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string message)
{
throw new ArgumentException(message);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string message, Exception innerException)
{
throw new ArgumentException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string name, string message)
{
throw new ArgumentException(message, name);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string name, string message, Exception innerException)
{
throw new ArgumentException(message, name, innerException);
}
/// <summary>
/// Throws a new <see cref="ArgumentNullException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <exception cref="ArgumentNullException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentNullException<T>(string name)
{
throw new ArgumentNullException(name);
}
/// <summary>
/// Throws a new <see cref="ArgumentNullException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentNullException<T>(string name, Exception innerException)
{
throw new ArgumentNullException(name, innerException);
}
/// <summary>
/// Throws a new <see cref="ArgumentNullException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentNullException<T>(string name, string message)
{
throw new ArgumentNullException(name, message);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentOutOfRangeException<T>(string name)
{
throw new ArgumentOutOfRangeException(name);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentOutOfRangeException<T>(string name, Exception innerException)
{
throw new ArgumentOutOfRangeException(name, innerException);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentOutOfRangeException<T>(string name, string message)
{
throw new ArgumentOutOfRangeException(name, message);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="value">The current argument value.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentOutOfRangeException<T>(string name, object value, string message)
{
throw new ArgumentOutOfRangeException(name, value, message);
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="COMException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowCOMException<T>(string message)
{
throw new COMException(message);
}
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The argument name.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowCOMException<T>(string message, Exception innerException)
{
throw new COMException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The argument name.</param>
/// <param name="error">The HRESULT of the errror to include.</param>
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowCOMException<T>(string message, int error)
{
throw new COMException(message, error);
}
/// <summary>
/// Throws a new <see cref="ExternalException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ExternalException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowExternalException<T>(string message)
{
throw new ExternalException(message);
}
/// <summary>
/// Throws a new <see cref="ExternalException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The argument name.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowExternalException<T>(string message, Exception innerException)
{
throw new ExternalException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="ExternalException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The argument name.</param>
/// <param name="error">The HRESULT of the errror to include.</param>
/// <exception cref="ExternalException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowExternalException<T>(string message, int error)
{
throw new ExternalException(message, error);
}
#endif
/// <summary>
/// Throws a new <see cref="FormatException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowFormatException<T>(string message)
{
throw new FormatException(message);
}
/// <summary>
/// Throws a new <see cref="FormatException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="FormatException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowFormatException<T>(string message, Exception innerException)
{
throw new FormatException(message, innerException);
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="InsufficientMemoryException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInsufficientMemoryException<T>(string message)
{
throw new InsufficientMemoryException(message);
}
/// <summary>
/// Throws a new <see cref="InsufficientMemoryException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="InsufficientMemoryException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInsufficientMemoryException<T>(string message, Exception innerException)
{
throw new InsufficientMemoryException(message, innerException);
}
#endif
/// <summary>
/// Throws a new <see cref="InvalidDataException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInvalidDataException<T>(string message)
{
throw new InvalidDataException(message);
}
/// <summary>
/// Throws a new <see cref="InvalidDataException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="InvalidDataException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInvalidDataException<T>(string message, Exception innerException)
{
throw new InvalidDataException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="InvalidOperationException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInvalidOperationException<T>(string message)
{
throw new InvalidOperationException(message);
}
/// <summary>
/// Throws a new <see cref="InvalidOperationException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowInvalidOperationException<T>(string message, Exception innerException)
{
throw new InvalidOperationException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="LockRecursionException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowLockRecursionException<T>(string message)
{
throw new LockRecursionException(message);
}
/// <summary>
/// Throws a new <see cref="LockRecursionException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="LockRecursionException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowLockRecursionException<T>(string message, Exception innerException)
{
throw new LockRecursionException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="MissingFieldException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingFieldException<T>(string message)
{
throw new MissingFieldException(message);
}
/// <summary>
/// Throws a new <see cref="MissingFieldException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="MissingFieldException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingFieldException<T>(string message, Exception innerException)
{
throw new MissingFieldException(message, innerException);
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="MissingFieldException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="className">The target class being inspected.</param>
/// <param name="fieldName">The target field being retrieved.</param>
/// <exception cref="MissingFieldException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingFieldException<T>(string className, string fieldName)
{
throw new MissingFieldException(className, fieldName);
}
#endif
/// <summary>
/// Throws a new <see cref="MissingMemberException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMemberException<T>(string message)
{
throw new MissingMemberException(message);
}
/// <summary>
/// Throws a new <see cref="MissingMemberException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="MissingMemberException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMemberException<T>(string message, Exception innerException)
{
throw new MissingMemberException(message, innerException);
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="MissingMemberException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="className">The target class being inspected.</param>
/// <param name="memberName">The target member being retrieved.</param>
/// <exception cref="MissingMemberException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMemberException<T>(string className, string memberName)
{
throw new MissingMemberException(className, memberName);
}
#endif
/// <summary>
/// Throws a new <see cref="MissingMethodException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMethodException<T>(string message)
{
throw new MissingMethodException(message);
}
/// <summary>
/// Throws a new <see cref="MissingMethodException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="MissingMethodException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMethodException<T>(string message, Exception innerException)
{
throw new MissingMethodException(message, innerException);
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="MissingMethodException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="className">The target class being inspected.</param>
/// <param name="methodName">The target method being retrieved.</param>
/// <exception cref="MissingMethodException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowMissingMethodException<T>(string className, string methodName)
{
throw new MissingMethodException(className, methodName);
}
#endif
/// <summary>
/// Throws a new <see cref="NotSupportedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowNotSupportedException<T>(string message)
{
throw new NotSupportedException(message);
}
/// <summary>
/// Throws a new <see cref="NotSupportedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowNotSupportedException<T>(string message, Exception innerException)
{
throw new NotSupportedException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="ObjectDisposedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="objectName">The name of the disposed object.</param>
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowObjectDisposedException<T>(string objectName)
{
throw new ObjectDisposedException(objectName);
}
/// <summary>
/// Throws a new <see cref="ObjectDisposedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="objectName">The name of the disposed object.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="ObjectDisposedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowObjectDisposedException<T>(string objectName, Exception innerException)
{
throw new ObjectDisposedException(objectName, innerException);
}
/// <summary>
/// Throws a new <see cref="ObjectDisposedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="objectName">The name of the disposed object.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ObjectDisposedException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowObjectDisposedException<T>(string objectName, string message)
{
throw new ObjectDisposedException(objectName, message);
}
/// <summary>
/// Throws a new <see cref="OperationCanceledException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowOperationCanceledException<T>(string message)
{
throw new OperationCanceledException(message);
}
/// <summary>
/// Throws a new <see cref="OperationCanceledException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="OperationCanceledException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowOperationCanceledException<T>(string message, Exception innerException)
{
throw new OperationCanceledException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="OperationCanceledException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowOperationCanceledException<T>(CancellationToken token)
{
throw new OperationCanceledException(token);
}
/// <summary>
/// Throws a new <see cref="OperationCanceledException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowOperationCanceledException<T>(string message, CancellationToken token)
{
throw new OperationCanceledException(message, token);
}
/// <summary>
/// Throws a new <see cref="OperationCanceledException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <param name="token">The <see cref="CancellationToken"/> in use.</param>
/// <exception cref="OperationCanceledException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowOperationCanceledException<T>(string message, Exception innerException, CancellationToken token)
{
throw new OperationCanceledException(message, innerException, token);
}
/// <summary>
/// Throws a new <see cref="PlatformNotSupportedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowPlatformNotSupportedException<T>(string message)
{
throw new PlatformNotSupportedException(message);
}
/// <summary>
/// Throws a new <see cref="PlatformNotSupportedException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="PlatformNotSupportedException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowPlatformNotSupportedException<T>(string message, Exception innerException)
{
throw new PlatformNotSupportedException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="SynchronizationLockException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowSynchronizationLockException<T>(string message)
{
throw new SynchronizationLockException(message);
}
/// <summary>
/// Throws a new <see cref="SynchronizationLockException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="SynchronizationLockException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowSynchronizationLockException<T>(string message, Exception innerException)
{
throw new SynchronizationLockException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="TimeoutException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowTimeoutException<T>(string message)
{
throw new TimeoutException(message);
}
/// <summary>
/// Throws a new <see cref="TimeoutException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="TimeoutException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowTimeoutException<T>(string message, Exception innerException)
{
throw new TimeoutException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="UnauthorizedAccessException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowUnauthorizedAccessException<T>(string message)
{
throw new UnauthorizedAccessException(message);
}
/// <summary>
/// Throws a new <see cref="UnauthorizedAccessException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="UnauthorizedAccessException">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowUnauthorizedAccessException<T>(string message, Exception innerException)
{
throw new UnauthorizedAccessException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="Win32Exception"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="error">The Win32 error code associated with this exception.</param>
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowWin32Exception<T>(int error)
{
throw new Win32Exception(error);
}
/// <summary>
/// Throws a new <see cref="Win32Exception"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="error">The Win32 error code associated with this exception.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowWin32Exception<T>(int error, string message)
{
throw new Win32Exception(error, message);
}
/// <summary>
/// Throws a new <see cref="Win32Exception"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowWin32Exception<T>(string message)
{
throw new Win32Exception(message);
}
/// <summary>
/// Throws a new <see cref="Win32Exception"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="message">The message to include in the exception.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="Win32Exception">Thrown with the specified parameter.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowWin32Exception<T>(string message, Exception innerException)
{
throw new Win32Exception(message, innerException);
}
}
}

Просмотреть файл

@ -175,6 +175,41 @@ namespace Microsoft.Toolkit.Diagnostics
}
#if !NETSTANDARD1_4
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="COMException">Thrown with the specified parameter.</exception>
[DoesNotReturn]
public static void ThrowCOMException(string message)
{
throw new COMException(message);
}
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <param name="message">The argument name.</param>
/// <param name="innerException">The inner <see cref="Exception"/> to include.</param>
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
[DoesNotReturn]
public static void ThrowCOMException(string message, Exception innerException)
{
throw new COMException(message, innerException);
}
/// <summary>
/// Throws a new <see cref="COMException"/>.
/// </summary>
/// <param name="message">The argument name.</param>
/// <param name="error">The HRESULT of the errror to include.</param>
/// <exception cref="COMException">Thrown with the specified parameters.</exception>
[DoesNotReturn]
public static void ThrowCOMException(string message, int error)
{
throw new COMException(message, error);
}
/// <summary>
/// Throws a new <see cref="ExternalException"/>.
/// </summary>

Просмотреть файл

@ -9,6 +9,7 @@ This project incorporates components from the projects listed below. The origina
2. MichaeIDietrich/UwpNotificationNetCoreTest commit 5c1a4a3 (https://github.com/MichaeIDietrich/UwpNotificationNetCoreTest), used in DesktopNotificationManagerCompat.cs to support .NET Core 3.0.
3. lbugnion/mvvmlight commit 4cbf77c (https://github.com/lbugnion/mvvmlight), from which some APIs from the `Microsoft.Toolkit.Mvvm` package take inspiration from.
4. PrivateObject/PrivateType (https://github.com/microsoft/testfx/tree/664ac7c2ac9dbfbee9d2a0ef560cfd72449dfe34/src/TestFramework/Extension.Desktop), included in UnitTests.
5. QuinnDamerell/UniversalMarkdown (https://github.com/QuinnDamerell/UniversalMarkdown) contributed by Quinn Damerell and Paul Bartrum for the MarkdownTextBlock control, relicensed to this .NET Foundation project under the MIT license upon contribution in https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/772.
%% PedroLamas/DeferredEvents NOTICES AND INFORMATION BEGIN HERE
=========================================

Просмотреть файл

@ -36,6 +36,7 @@ namespace UnitTests.Diagnostics
[DataRow(typeof(ArgumentException))]
[DataRow(typeof(ArgumentNullException))]
[DataRow(typeof(ArgumentOutOfRangeException))]
[DataRow(typeof(COMException))]
[DataRow(typeof(ExternalException))]
[DataRow(typeof(FormatException))]
[DataRow(typeof(InsufficientMemoryException))]
@ -57,7 +58,8 @@ namespace UnitTests.Diagnostics
{
var methods = (
from method in typeof(ThrowHelper).GetMethods(BindingFlags.Public | BindingFlags.Static)
where method.Name == $"Throw{exceptionType.Name}"
where method.Name == $"Throw{exceptionType.Name}" &&
!method.IsGenericMethod
select method).ToArray();
foreach (var method in methods)
@ -78,5 +80,66 @@ namespace UnitTests.Diagnostics
}
}
}
[TestCategory("Guard")]
[TestMethod]
[DataRow(typeof(ArrayTypeMismatchException))]
[DataRow(typeof(ArgumentException))]
[DataRow(typeof(ArgumentNullException))]
[DataRow(typeof(ArgumentOutOfRangeException))]
[DataRow(typeof(COMException))]
[DataRow(typeof(ExternalException))]
[DataRow(typeof(FormatException))]
[DataRow(typeof(InsufficientMemoryException))]
[DataRow(typeof(InvalidDataException))]
[DataRow(typeof(InvalidOperationException))]
[DataRow(typeof(LockRecursionException))]
[DataRow(typeof(MissingFieldException))]
[DataRow(typeof(MissingMemberException))]
[DataRow(typeof(MissingMethodException))]
[DataRow(typeof(NotSupportedException))]
[DataRow(typeof(ObjectDisposedException))]
[DataRow(typeof(OperationCanceledException))]
[DataRow(typeof(PlatformNotSupportedException))]
[DataRow(typeof(SynchronizationLockException))]
[DataRow(typeof(TimeoutException))]
[DataRow(typeof(UnauthorizedAccessException))]
[DataRow(typeof(Win32Exception))]
public void Test_ThrowHelper_Generic_Throw(Type exceptionType)
{
var methods = (
from method in typeof(ThrowHelper).GetMethods(BindingFlags.Public | BindingFlags.Static)
where method.Name == $"Throw{exceptionType.Name}" &&
method.IsGenericMethod
select method).ToArray();
foreach (var method in methods)
{
// Prepare the parameters with the default value
var parameters = (
from parameter in method.GetParameters()
select DefaultValues[parameter.ParameterType]).ToArray();
// Invoke with value type
try
{
method.MakeGenericMethod(typeof(int)).Invoke(null, parameters);
}
catch (TargetInvocationException e)
{
Assert.IsInstanceOfType(e.InnerException, exceptionType);
}
// Invoke with reference type
try
{
method.MakeGenericMethod(typeof(string)).Invoke(null, parameters);
}
catch (TargetInvocationException e)
{
Assert.IsInstanceOfType(e.InnerException, exceptionType);
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.Converters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
using Windows.UI.Xaml;
namespace UnitTests.Converters
{
[TestClass]
public class Test_TypeToObjectConverter
{
[TestCategory("Converters")]
[UITestMethod]
public void Test_StringConvertStringToVisibility()
{
var converter = new TypeToObjectConverter
{
TrueValue = Visibility.Visible,
FalseValue = Visibility.Collapsed,
Type = typeof(string)
};
var result = converter.Convert("anything", typeof(Visibility), null, "en-us");
Assert.AreEqual(Visibility.Visible, result);
}
[TestCategory("Converters")]
[UITestMethod]
public void Test_StringDoesntConvertBoolToVisibility()
{
var converter = new TypeToObjectConverter
{
TrueValue = Visibility.Visible,
FalseValue = Visibility.Collapsed,
Type = typeof(string)
};
var result = converter.Convert(true, typeof(Visibility), null, "en-us");
Assert.AreEqual(Visibility.Collapsed, result);
}
[TestCategory("Converters")]
[UITestMethod]
public void Test_StringConvertStringToVisibilityWithNegateTrue()
{
var converter = new TypeToObjectConverter
{
TrueValue = Visibility.Visible,
FalseValue = Visibility.Collapsed,
Type = typeof(string)
};
var result = converter.Convert("anything", typeof(Visibility), "true", "en-us");
Assert.AreEqual(Visibility.Collapsed, result);
}
}
}

Просмотреть файл

@ -133,6 +133,7 @@
<Compile Include="Converters\Test_EmptyCollectionToObjectConverter.cs" />
<Compile Include="Converters\Test_EmptyStringToObjectConverter.cs" />
<Compile Include="Converters\Test_StringFormatConverter.cs" />
<Compile Include="Converters\Test_TypeToObjectConverter.cs" />
<Compile Include="Extensions\Helpers\ObjectWithNullableBoolProperty.cs" />
<Compile Include="Extensions\Test_BitmapIconExtensionMarkupExtension.cs" />
<Compile Include="Extensions\Test_FontIconSourceExtensionMarkupExtension.cs" />

Просмотреть файл

@ -34,8 +34,7 @@ namespace UnitTests.XamlIslands.UWPApp
_textToolbar = new TextToolbar
{
Editor = richEditBox,
IsEnabled = true,
Format = Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.Format.RichText
IsEnabled = true
};
var grid = new Grid

Просмотреть файл

@ -117,6 +117,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{88C6FFBE-3
ThirdPartyNotices.txt = ThirdPartyNotices.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI.Controls.Markdown", "Microsoft.Toolkit.Uwp.UI.Controls.Markdown\Microsoft.Toolkit.Uwp.UI.Controls.Markdown.csproj", "{6FEDF199-B052-49DD-8F3E-2A9224998E0F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Design", "Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Design\Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Design.csproj", "{67FE47A0-CA93-4680-B770-A0A48C1DBC40}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
UnitTests\UnitTests.Shared\UnitTests.Shared.projitems*{4e9466d1-d5aa-46ac-801b-c8fdab79f0d4}*SharedItemsImports = 13
@ -622,6 +626,7 @@ Global
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|ARM.ActiveCfg = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|ARM.Build.0 = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|ARM64.ActiveCfg = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|ARM64.Build.0 = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|x64.ActiveCfg = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|x64.Build.0 = Release|x86
{7AEFC959-ED7C-4D96-9E92-72609B40FBE0}.Release|x86.ActiveCfg = Release|x86
@ -645,6 +650,7 @@ Global
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|ARM.ActiveCfg = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|ARM.Build.0 = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|ARM64.ActiveCfg = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|ARM64.Build.0 = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|x64.ActiveCfg = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|x64.Build.0 = Release|x86
{6BD0BA4A-DE6D-3E87-8F83-63518C31ECD1}.Release|x86.ActiveCfg = Release|x86
@ -770,15 +776,10 @@ Global
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Debug|x86.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Debug|x86.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|Any CPU.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|Any CPU.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|ARM.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|ARM.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|ARM64.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|ARM64.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|x64.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|x64.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|x86.ActiveCfg = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Native|x86.Build.0 = Debug|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Release|Any CPU.Build.0 = Release|Any CPU
{D82AE6E1-E612-434E-ACB2-363EE48738D3}.Release|ARM.ActiveCfg = Release|Any CPU
@ -825,15 +826,10 @@ Global
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Debug|x86.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Debug|x86.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|Any CPU.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|Any CPU.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|ARM.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|ARM.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|ARM64.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|ARM64.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|x64.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|x64.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|x86.ActiveCfg = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Native|x86.Build.0 = Debug|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Release|Any CPU.Build.0 = Release|Any CPU
{CB444381-18BA-4A51-BB32-3A498BCC1E99}.Release|ARM.ActiveCfg = Release|Any CPU
@ -1002,6 +998,55 @@ Global
{804D0681-52F6-4E61-864A-699F0AB44B20}.Release|x86.ActiveCfg = Release|x86
{804D0681-52F6-4E61-864A-699F0AB44B20}.Release|x86.Build.0 = Release|x86
{804D0681-52F6-4E61-864A-699F0AB44B20}.Release|x86.Deploy.0 = Release|x86
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|ARM.Build.0 = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|ARM64.Build.0 = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|x64.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|x64.Build.0 = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|x86.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Debug|x86.Build.0 = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Native|Any CPU.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Native|ARM.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Native|ARM64.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Native|x64.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Native|x86.ActiveCfg = Debug|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|Any CPU.Build.0 = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|ARM.ActiveCfg = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|ARM.Build.0 = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|ARM64.ActiveCfg = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|ARM64.Build.0 = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|x64.ActiveCfg = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|x64.Build.0 = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|x86.ActiveCfg = Release|Any CPU
{6FEDF199-B052-49DD-8F3E-2A9224998E0F}.Release|x86.Build.0 = Release|Any CPU
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|Any CPU.ActiveCfg = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|Any CPU.Build.0 = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|ARM.ActiveCfg = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|ARM.Build.0 = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|ARM64.ActiveCfg = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|x64.ActiveCfg = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|x64.Build.0 = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|x86.ActiveCfg = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Debug|x86.Build.0 = Debug|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Native|Any CPU.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Native|ARM.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Native|ARM64.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Native|x64.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Native|x86.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|Any CPU.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|Any CPU.Build.0 = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|ARM.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|ARM.Build.0 = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|ARM64.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|ARM64.Build.0 = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|x64.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|x64.Build.0 = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|x86.ActiveCfg = Release|x86
{67FE47A0-CA93-4680-B770-A0A48C1DBC40}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1035,6 +1080,8 @@ Global
{C79029AF-2E9B-4466-BAC4-1A41B281EAE6} = {B30036C4-D514-4E5B-A323-587A061772CE}
{804D0681-52F6-4E61-864A-699F0AB44B20} = {C79029AF-2E9B-4466-BAC4-1A41B281EAE6}
{88C6FFBE-322D-4CEA-842B-B2CB281D357D} = {CFA75BE0-5A44-45DE-8114-426A605B062B}
{6FEDF199-B052-49DD-8F3E-2A9224998E0F} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC}
{67FE47A0-CA93-4680-B770-A0A48C1DBC40} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5403B0C4-F244-4F73-A35C-FE664D0F4345}