Skip to content

Commit

Permalink
add RichSuggestBox to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
huynhsontung committed Jan 3, 2021
1 parent 8e2b3af commit c7894bb
Show file tree
Hide file tree
Showing 11 changed files with 953 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@
<None Include="$(OutDir)\Design\$(MSBuildProjectName).Design*.dll;$(OutDir)\Design\$(MSBuildProjectName).Design*.pdb" Pack="true" PackagePath="lib\$(TargetFramework)\Design" />
</ItemGroup>

<ItemGroup>
<Page Remove="RichSuggestBox\RichSuggestBox.xaml" />
</ItemGroup>

<ItemGroup>
<PRIResource Include="Strings\en-us\Resources.resw" />
</ItemGroup>

<ItemGroup>
<None Update="RichSuggestBox\RichSuggestBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>

<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Windows.UI.Xaml.Controls;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal class PlainTextCommandBarFlyout : TextCommandBarFlyout
{
public PlainTextCommandBarFlyout()
{
Opening += (sender, o) =>
{
PrimaryCommands.Clear();

// TODO: Limit Pasting to plain-text only
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
public partial class RichSuggestBox
{
public event TypedEventHandler<RichSuggestBox, SuggestionsRequestedEventArgs> SuggestionsRequested;

public event TypedEventHandler<RichSuggestBox, SuggestionChosenEventArgs> SuggestionChosen;

public event TypedEventHandler<RichEditBox, RoutedEventArgs> TextChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System.Collections.ObjectModel;
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
public partial class RichSuggestBox
{
public static readonly DependencyProperty PlaceholderTextProperty =
DependencyProperty.Register(
nameof(PlaceholderText),
typeof(string),
typeof(RichSuggestBox),
new PropertyMetadata(string.Empty));

public static readonly DependencyProperty RichEditBoxStyleProperty =
DependencyProperty.Register(
nameof(RichEditBoxStyle),
typeof(Style),
typeof(RichSuggestBox),
new PropertyMetadata(null));

public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register(
nameof(Header),
typeof(object),
typeof(RichSuggestBox),
new PropertyMetadata(null));

public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register(
nameof(Description),
typeof(object),
typeof(RichSuggestBox),
new PropertyMetadata(null));

public static readonly DependencyProperty TextWrappingProperty =
DependencyProperty.Register(
nameof(TextWrapping),
typeof(TextWrapping),
typeof(RichSuggestBox),
new PropertyMetadata(TextWrapping.NoWrap));

public static readonly DependencyProperty ClipboardCopyFormatProperty =
DependencyProperty.Register(
nameof(ClipboardCopyFormat),
typeof(RichEditClipboardFormat),
typeof(RichSuggestBox),
new PropertyMetadata(RichEditClipboardFormat.PlainText));

public static readonly DependencyProperty SuggestionBackgroundProperty =
DependencyProperty.Register(
nameof(SuggestionBackground),
typeof(SolidColorBrush),
typeof(RichSuggestBox),
new PropertyMetadata(null));

public static readonly DependencyProperty SuggestionForegroundProperty =
DependencyProperty.Register(
nameof(SuggestionForeground),
typeof(SolidColorBrush),
typeof(RichSuggestBox),
new PropertyMetadata(null));

public static readonly DependencyProperty PrefixesProperty =
DependencyProperty.Register(
nameof(Prefixes),
typeof(string),
typeof(RichSuggestBox),
new PropertyMetadata("@", OnPrefixesChanged));

public string PlaceholderText
{
get => (string)GetValue(PlaceholderTextProperty);
set => SetValue(PlaceholderTextProperty, value);
}

public Style RichEditBoxStyle
{
get => (Style)GetValue(RichEditBoxStyleProperty);
set => SetValue(RichEditBoxStyleProperty, value);
}

public object Header
{
get => GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}

public object Description
{
get => GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}

public TextWrapping TextWrapping
{
get => (TextWrapping)GetValue(TextWrappingProperty);
set => SetValue(TextWrappingProperty, value);
}

public RichEditClipboardFormat ClipboardCopyFormat
{
get => (RichEditClipboardFormat)GetValue(ClipboardCopyFormatProperty);
set => SetValue(ClipboardCopyFormatProperty, value);
}

public SolidColorBrush SuggestionBackground
{
get => (SolidColorBrush)GetValue(SuggestionBackgroundProperty);
set => SetValue(SuggestionBackgroundProperty, value);
}

public SolidColorBrush SuggestionForeground
{
get => (SolidColorBrush)GetValue(SuggestionForegroundProperty);
set => SetValue(SuggestionForegroundProperty, value);
}

public string Prefixes
{
get => (string)GetValue(PrefixesProperty);
set => SetValue(PrefixesProperty, value);
}

/// <summary>
/// Gets object used for lock
/// </summary>
protected object LockObj { get; }

public RichEditTextDocument TextDocument => _richEditBox?.TextDocument;

public ReadOnlyObservableCollection<SuggestionInfo> Tokens { get; }
}
}
Loading

0 comments on commit c7894bb

Please sign in to comment.