This commit is contained in:
Tung Huynh 2021-01-21 12:33:55 -08:00
Родитель ce3726f732
Коммит 91093cf56e
7 изменённых файлов: 288 добавлений и 0 удалений

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

@ -506,6 +506,10 @@
<Compile Include="SamplePages\MetadataControl\MetadataControlPage.xaml.cs">
<DependentUpon>MetadataControlPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\RichSuggestBox\RichSuggestBoxPage.xaml.cs">
<DependentUpon>RichSuggestBoxPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\RichSuggestBox\SuggestionTemplateSelector.cs" />
<Compile Include="SamplePages\TilesBrush\TilesBrushPage.xaml.cs">
<DependentUpon>TilesBrushPage.xaml</DependentUpon>
</Compile>
@ -627,6 +631,7 @@
<SubType>Designer</SubType>
</Content>
<Content Include="SamplePages\KeyDownTriggerBehavior\KeyDownTriggerBehaviorXaml.bind" />
<Content Include="SamplePages\RichSuggestBox\RichSuggestBoxCode.bind" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
@ -986,6 +991,14 @@
<Content Include="SamplePages\Primitives\SwitchPresenter.bind">
<SubType>Designer</SubType>
</Content>
<Content Include="SamplePages\RichSuggestBox\RichSuggestBoxXaml.bind">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Content>
<Page Include="SamplePages\RichSuggestBox\RichSuggestBoxPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

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

@ -0,0 +1,27 @@
private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
{
if (args.Prefix == "#")
{
args.Format.Background = Colors.DarkOrange;
args.Format.Foreground = Colors.OrangeRed;
args.Text = ((SampleDataType)args.SelectedItem).Text;
}
else
{
args.Text = ((SampleEmailDataType)args.SelectedItem).DisplayName;
}
}
private void SuggestingBox_OnSuggestionsRequested(RichSuggestBox sender, SuggestionsRequestedEventArgs args)
{
if (args.Prefix == "#")
{
sender.ItemsSource =
this._samples.Where(x => x.Text.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
}
else
{
sender.ItemsSource =
this._emailSamples.Where(x => x.DisplayName.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
}
}

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

@ -0,0 +1,19 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.RichSuggestBoxPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<ResourceDictionary>
<local:SuggestionTemplateSelector x:Key="SuggestionTemplateSelector" />
</ResourceDictionary>
</Page.Resources>
<Grid Visibility="Collapsed">
<controls:RichSuggestBox />
<ListView />
</Grid>
</Page>

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

@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Toolkit.Uwp.UI.Extensions;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class RichSuggestBoxPage : Page, IXamlRenderListener
{
private readonly List<SampleEmailDataType> _emailSamples = new List<SampleEmailDataType>()
{
new SampleEmailDataType() { FirstName = "Marcus", FamilyName = "Perryman" },
new SampleEmailDataType() { FirstName = "Michael", FamilyName = "Hawker" },
new SampleEmailDataType() { FirstName = "Matt", FamilyName = "Lacey" },
new SampleEmailDataType() { FirstName = "Alexandre", FamilyName = "Chohfi" },
new SampleEmailDataType() { FirstName = "Filip", FamilyName = "Wallberg" },
new SampleEmailDataType() { FirstName = "Shane", FamilyName = "Weaver" },
new SampleEmailDataType() { FirstName = "Vincent", FamilyName = "Gromfeld" },
new SampleEmailDataType() { FirstName = "Sergio", FamilyName = "Pedri" },
new SampleEmailDataType() { FirstName = "Alex", FamilyName = "Wilber" },
new SampleEmailDataType() { FirstName = "Allan", FamilyName = "Deyoung" },
new SampleEmailDataType() { FirstName = "Adele", FamilyName = "Vance" },
new SampleEmailDataType() { FirstName = "Grady", FamilyName = "Archie" },
new SampleEmailDataType() { FirstName = "Megan", FamilyName = "Bowen" },
new SampleEmailDataType() { FirstName = "Ben", FamilyName = "Walters" },
new SampleEmailDataType() { FirstName = "Debra", FamilyName = "Berger" },
new SampleEmailDataType() { FirstName = "Emily", FamilyName = "Braun" },
new SampleEmailDataType() { FirstName = "Christine", FamilyName = "Cline" },
new SampleEmailDataType() { FirstName = "Enrico", FamilyName = "Catteneo" },
new SampleEmailDataType() { FirstName = "Davit", FamilyName = "Badalyan" },
new SampleEmailDataType() { FirstName = "Diego", FamilyName = "Siciliani" },
new SampleEmailDataType() { FirstName = "Raul", FamilyName = "Razo" },
new SampleEmailDataType() { FirstName = "Miriam", FamilyName = "Graham" },
new SampleEmailDataType() { FirstName = "Lynne", FamilyName = "Robbins" },
new SampleEmailDataType() { FirstName = "Lydia", FamilyName = "Holloway" },
new SampleEmailDataType() { FirstName = "Nestor", FamilyName = "Wilke" },
new SampleEmailDataType() { FirstName = "Patti", FamilyName = "Fernandez" },
new SampleEmailDataType() { FirstName = "Pradeep", FamilyName = "Gupta" },
new SampleEmailDataType() { FirstName = "Joni", FamilyName = "Sherman" },
new SampleEmailDataType() { FirstName = "Isaiah", FamilyName = "Langer" },
new SampleEmailDataType() { FirstName = "Irvin", FamilyName = "Sayers" },
};
private readonly List<SampleDataType> _samples = new List<SampleDataType>()
{
new SampleDataType() { Text = "Account", Icon = Symbol.Account },
new SampleDataType() { Text = "Add Friend", Icon = Symbol.AddFriend },
new SampleDataType() { Text = "Attach", Icon = Symbol.Attach },
new SampleDataType() { Text = "Attach Camera", Icon = Symbol.AttachCamera },
new SampleDataType() { Text = "Audio", Icon = Symbol.Audio },
new SampleDataType() { Text = "Block Contact", Icon = Symbol.BlockContact },
new SampleDataType() { Text = "Calculator", Icon = Symbol.Calculator },
new SampleDataType() { Text = "Calendar", Icon = Symbol.Calendar },
new SampleDataType() { Text = "Camera", Icon = Symbol.Camera },
new SampleDataType() { Text = "Contact", Icon = Symbol.Contact },
new SampleDataType() { Text = "Favorite", Icon = Symbol.Favorite },
new SampleDataType() { Text = "Link", Icon = Symbol.Link },
new SampleDataType() { Text = "Mail", Icon = Symbol.Mail },
new SampleDataType() { Text = "Map", Icon = Symbol.Map },
new SampleDataType() { Text = "Phone", Icon = Symbol.Phone },
new SampleDataType() { Text = "Pin", Icon = Symbol.Pin },
new SampleDataType() { Text = "Rotate", Icon = Symbol.Rotate },
new SampleDataType() { Text = "Rotate Camera", Icon = Symbol.RotateCamera },
new SampleDataType() { Text = "Send", Icon = Symbol.Send },
new SampleDataType() { Text = "Tags", Icon = Symbol.Tag },
new SampleDataType() { Text = "UnFavorite", Icon = Symbol.UnFavorite },
new SampleDataType() { Text = "UnPin", Icon = Symbol.UnPin },
new SampleDataType() { Text = "Zoom", Icon = Symbol.Zoom },
new SampleDataType() { Text = "ZoomIn", Icon = Symbol.ZoomIn },
new SampleDataType() { Text = "ZoomOut", Icon = Symbol.ZoomOut },
};
private RichSuggestBox _rsb;
public RichSuggestBoxPage()
{
this.InitializeComponent();
Loaded += (sender, e) => { this.OnXamlRendered(this); };
}
public void OnXamlRendered(FrameworkElement control)
{
if (this._rsb != null)
{
this._rsb.SuggestionChosen -= this.SuggestingBox_OnSuggestionChosen;
this._rsb.SuggestionsRequested -= this.SuggestingBox_OnSuggestionsRequested;
}
if (control.FindChildByName("SuggestingBox") is RichSuggestBox rsb)
{
this._rsb = rsb;
this._rsb.SuggestionChosen += this.SuggestingBox_OnSuggestionChosen;
this._rsb.SuggestionsRequested += this.SuggestingBox_OnSuggestionsRequested;
}
if (control.FindChildByName("TokenListView") is ListView tls)
{
tls.ItemsSource = this._rsb?.Tokens;
}
}
private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
{
if (args.Prefix == "#")
{
args.Format.Background = Colors.DarkOrange;
args.Format.Foreground = Colors.OrangeRed;
args.Text = ((SampleDataType)args.SelectedItem).Text;
}
else
{
args.Text = ((SampleEmailDataType)args.SelectedItem).DisplayName;
}
}
private void SuggestingBox_OnSuggestionsRequested(RichSuggestBox sender, SuggestionsRequestedEventArgs args)
{
if (args.Prefix == "#")
{
sender.ItemsSource =
this._samples.Where(x => x.Text.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
}
else
{
sender.ItemsSource =
this._emailSamples.Where(x => x.DisplayName.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
}
}
}
}

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

@ -0,0 +1,61 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<ResourceDictionary>
<DataTemplate x:Key="EmailTemplate">
<TextBlock Text="{Binding EmailAddress}" />
</DataTemplate>
<DataTemplate x:Key="DataTemplate">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding Icon}" />
<TextBlock Padding="4,0,0,0"
Text="{Binding Text}" />
</StackPanel>
</DataTemplate>
<local:SuggestionTemplateSelector x:Key="SuggestionTemplateSelector"
Data="{StaticResource DataTemplate}"
Person="{StaticResource EmailTemplate}" />
<DataTemplate x:Key="TokenTemplate">
<StackPanel Margin="0,4,0,4"
Orientation="Vertical">
<TextBlock>
Text: <Run Text="{Binding DisplayText}" /></TextBlock>
<TextBlock>
Position: <Run Text="{Binding Position}" /></TextBlock>
<TextBlock>
Id: <Run Text="{Binding Id}" /></TextBlock>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</Page.Resources>
<Grid Margin="40">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:RichSuggestBox x:Name="SuggestingBox"
MaxHeight="400"
HorizontalAlignment="Stretch"
ClipboardCopyFormat="AllFormats"
Header="RichSuggestBox:"
ItemTemplateSelector="{StaticResource SuggestionTemplateSelector}"
Prefixes="@#"
TextWrapping="Wrap" />
<ListView x:Name="TokenListView"
Grid.Row="1"
Margin="0,16,0,0"
HorizontalAlignment="Stretch"
ItemTemplate="{StaticResource TokenTemplate}" />
</Grid>
</Page>

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

@ -0,0 +1,17 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
public class SuggestionTemplateSelector : DataTemplateSelector
{
public DataTemplate Person { get; set; }
public DataTemplate Data { get; set; }
protected override DataTemplate SelectTemplateCore(object item)
{
return item is SampleEmailDataType ? this.Person : this.Data;
}
}
}

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

@ -484,6 +484,17 @@
"XamlCodeFile": "/SamplePages/Primitives/ConstrainedBox.bind",
"Icon": "/SamplePages/Primitives/ConstrainedBox.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/ConstrainedBox.md"
},
{
"Name": "RichSuggestBox",
"Type": "RichSuggestBoxPage",
"Subcategory": "Input",
"About": "A text input control that makes suggestions and keeps track of data token items in a rich document.",
"CodeUrl": "https://github.com/huynhsontung/WindowsCommunityToolkit/tree/RichSuggestBox/Microsoft.Toolkit.Uwp.UI.Controls/RichSuggestBox",
"CodeFile": "RichSuggestBoxCode.bind",
"XamlCodeFile": "RichSuggestBoxXaml.bind",
"Icon": "/SamplePages/TokenizingTextBox/TokenizingTextBox.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/TokenizingTextBox.md"
}
]
},