Skip to content

Commit 73e5f15

Browse files
committed
update sample code bind
1 parent 3587c40 commit 73e5f15

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
private void SuggestingBox_OnPointerMoved(object sender, PointerRoutedEventArgs e)
1+
private void SuggestingBox_OnTokenPointerOver(RichSuggestBox sender, RichSuggestTokenPointerOverEventArgs args)
22
{
3-
this._pointerPoint = e.GetCurrentPoint((UIElement)sender);
4-
}
3+
var flyout = (Flyout)FlyoutBase.GetAttachedFlyout(sender);
4+
var pointerPosition = args.CurrentPoint.Position;
55

6-
private void SuggestingBox_OnTokenHovered(RichSuggestBox sender, RichSuggestTokenEventArgs args)
7-
{
8-
this._hoveringTimer.Debounce(() =>
6+
if (flyout?.Content is ContentPresenter cp && sender.TextDocument.Selection.Type != SelectionType.Normal &&
7+
(!flyout.IsOpen || cp.Content != args.Token.Item))
98
{
10-
var flyout = (Flyout)FlyoutBase.GetAttachedFlyout(sender);
11-
if (flyout?.Content is ContentPresenter cp && sender.TextDocument.Selection.Type != SelectionType.Normal &&
12-
(!flyout.IsOpen || cp.Content != args.Token.Item))
9+
this._dispatcherQueue.TryEnqueue(() =>
1310
{
1411
cp.Content = args.Token.Item;
1512
flyout.ShowAt(sender, new FlyoutShowOptions
1613
{
17-
Position = this._pointerPoint.Position,
18-
ExclusionRect = args.Rect,
19-
ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway
14+
Position = pointerPosition,
15+
ExclusionRect = sender.GetRectFromRange(args.Range),
16+
ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway,
2017
});
21-
}
22-
}, TimeSpan.FromMilliseconds(200));
18+
});
19+
}
2320
}
2421

2522
private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
2623
{
2724
if (args.Prefix == "#")
2825
{
29-
args.Format.Background = Colors.DarkOrange;
30-
args.Format.Foreground = Colors.OrangeRed;
31-
args.Text = ((SampleDataType)args.SelectedItem).Text;
26+
args.Format.BackgroundColor = Colors.DarkOrange;
27+
args.Format.ForegroundColor = Colors.OrangeRed;
28+
args.Format.Bold = FormatEffect.On;
29+
args.Format.Italic = FormatEffect.On;
30+
args.DisplayText = ((SampleDataType)args.SelectedItem).Text;
3231
}
3332
else
3433
{
35-
args.Text = ((SampleEmailDataType)args.SelectedItem).DisplayName;
34+
args.DisplayText = ((SampleEmailDataType)args.SelectedItem).DisplayName;
3635
}
3736
}
3837

39-
private void SuggestingBox_OnSuggestionsRequested(RichSuggestBox sender, SuggestionsRequestedEventArgs args)
38+
private void SuggestingBox_OnSuggestionRequested(RichSuggestBox sender, SuggestionRequestedEventArgs args)
4039
{
4140
if (args.Prefix == "#")
4241
{
4342
sender.ItemsSource =
44-
this._samples.Where(x => x.Text.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
43+
this._samples.Where(x => x.Text.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
4544
}
4645
else
4746
{
4847
sender.ItemsSource =
49-
this._emailSamples.Where(x => x.DisplayName.Contains(args.Query, StringComparison.OrdinalIgnoreCase));
48+
this._emailSamples.Where(x => x.DisplayName.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
5049
}
51-
}
50+
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/RichSuggestBox/RichSuggestBoxXaml.bind

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -83,7 +83,7 @@
8383
ClipboardCopyFormat="PlainText"
8484
ClipboardPasteFormat="PlainText"
8585
DisabledFormattingAccelerators="All"
86-
Header="Plain text suggest box with on token selected flyout"
86+
Header="Plain text suggest box with on token pointer over flyout"
8787
ItemTemplate="{StaticResource EmailTemplate}"
8888
Prefixes="@"
8989
FlyoutBase.AttachedFlyout="{StaticResource TokenSelectedFlyout}" />

0 commit comments

Comments
 (0)