Skip to content

Commit 5984f29

Browse files
committed
pr comments
1 parent 9dad997 commit 5984f29

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/MetadataControl/MetadataControlPage.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public sealed partial class MetadataControlPage : Page, IXamlRenderListener
2020
private static readonly string[] Labels = "Lorem ipsum dolor sit amet consectetur adipiscing elit".Split(" ");
2121

2222
private readonly Random _random;
23-
private readonly ObservableCollection<MetadataUnit> _units;
23+
private readonly ObservableCollection<MetadataItem> _units;
2424
private readonly DelegateCommand<object> _command;
2525
private MetadataControl _metadataControl;
2626

2727
public MetadataControlPage()
2828
{
2929
_random = new Random();
30-
_units = new ObservableCollection<MetadataUnit>();
30+
_units = new ObservableCollection<MetadataItem>();
3131
_command = new DelegateCommand<object>(OnExecuteCommand);
3232
InitializeComponent();
3333
Setup();
@@ -38,21 +38,21 @@ public void OnXamlRendered(FrameworkElement control)
3838
_metadataControl = control.FindChildByName("metadataControl") as MetadataControl;
3939
if (_metadataControl != null)
4040
{
41-
_metadataControl.MetadataUnits = _units;
41+
_metadataControl.Items = _units;
4242
}
4343
}
4444

4545
private void Setup()
4646
{
4747
SampleController.Current.RegisterNewCommand("Add label", (sender, args) =>
4848
{
49-
_units.Add(new MetadataUnit { Label = GetRandomLabel() });
49+
_units.Add(new MetadataItem { Label = GetRandomLabel() });
5050
});
5151

5252
SampleController.Current.RegisterNewCommand("Add command", (sender, args) =>
5353
{
5454
var label = GetRandomLabel();
55-
_units.Add(new MetadataUnit
55+
_units.Add(new MetadataItem
5656
{
5757
Label = label,
5858
Command = _command,

Microsoft.Toolkit.Uwp.UI.Controls/MetadataControl/MetadataControl.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Microsoft.Toolkit.Uwp.UI.Controls
1515
{
1616
/// <summary>
17-
/// Display <see cref="MetadataUnit"/>s separated by bullets.
17+
/// Display <see cref="MetadataItem"/>s separated by bullets.
1818
/// </summary>
1919
[TemplatePart(Name = TextContainerPart, Type = typeof(TextBlock))]
2020
public sealed class MetadataControl : Control
@@ -38,13 +38,22 @@ public sealed class MetadataControl : Control
3838
new PropertyMetadata(", ", OnPropertyChanged));
3939

4040
/// <summary>
41-
/// The DP to store the <see cref="MetadataUnits"/> property value.
41+
/// The DP to store the <see cref="Items"/> property value.
4242
/// </summary>
43-
public static readonly DependencyProperty MetadataUnitsProperty = DependencyProperty.Register(
44-
nameof(MetadataUnits),
45-
typeof(IEnumerable<MetadataUnit>),
43+
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register(
44+
nameof(Items),
45+
typeof(IEnumerable<MetadataItem>),
4646
typeof(MetadataControl),
47-
new PropertyMetadata(null, OnMetadataUnitsChanged));
47+
new PropertyMetadata(null, OnMetadataItemsChanged));
48+
49+
/// <summary>
50+
/// The DP to store the TextBlockStyle value.
51+
/// </summary>
52+
public static readonly DependencyProperty TextBlockStyleProperty = DependencyProperty.Register(
53+
nameof(TextBlockStyle),
54+
typeof(Style),
55+
typeof(MetadataControl),
56+
new PropertyMetadata(null));
4857

4958
private const string TextContainerPart = "TextContainer";
5059

@@ -60,7 +69,7 @@ public MetadataControl()
6069
}
6170

6271
/// <summary>
63-
/// Gets or sets the separator to display between the <see cref="MetadataUnit"/>.
72+
/// Gets or sets the separator to display between the <see cref="MetadataItem"/>.
6473
/// </summary>
6574
public string Separator
6675
{
@@ -78,13 +87,22 @@ public string AccessibleSeparator
7887
}
7988

8089
/// <summary>
81-
/// Gets or sets he <see cref="MetadataUnit"/> to display in the control.
90+
/// Gets or sets the <see cref="MetadataItem"/> to display in the control.
8291
/// If it implements <see cref="INotifyCollectionChanged"/>, the control will automatically update itself.
8392
/// </summary>
84-
public IEnumerable<MetadataUnit> MetadataUnits
93+
public IEnumerable<MetadataItem> Items
94+
{
95+
get => (IEnumerable<MetadataItem>)GetValue(ItemsProperty);
96+
set => SetValue(ItemsProperty, value);
97+
}
98+
99+
/// <summary>
100+
/// Gets or sets the <see cref="Style"/> to use on the inner <see cref="TextBlock"/> control.
101+
/// </summary>
102+
public Style TextBlockStyle
85103
{
86-
get => (IEnumerable<MetadataUnit>)GetValue(MetadataUnitsProperty);
87-
set => SetValue(MetadataUnitsProperty, value);
104+
get => (Style)GetValue(TextBlockStyleProperty);
105+
set => SetValue(TextBlockStyleProperty, value);
88106
}
89107

90108
/// <inheritdoc/>
@@ -94,7 +112,7 @@ protected override void OnApplyTemplate()
94112
Update();
95113
}
96114

97-
private static void OnMetadataUnitsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
115+
private static void OnMetadataItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
98116
{
99117
var control = (MetadataControl)d;
100118
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) => control.Update();
@@ -127,7 +145,7 @@ private void Update()
127145

128146
_textContainer.Inlines.Clear();
129147

130-
if (MetadataUnits is null)
148+
if (Items is null)
131149
{
132150
AutomationProperties.SetName(_textContainer, string.Empty);
133151
NotifyLiveRegionChanged();
@@ -136,7 +154,7 @@ private void Update()
136154

137155
Inline unitToAppend;
138156
var accessibleString = new StringBuilder();
139-
foreach (var unit in MetadataUnits)
157+
foreach (var unit in Items)
140158
{
141159
if (_textContainer.Inlines.Count > 0)
142160
{

Microsoft.Toolkit.Uwp.UI.Controls/MetadataControl/MetadataControl.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<ResourceDictionary
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
54

65
<Style TargetType="controls:MetadataControl">
76
<Setter Property="Template">
87
<Setter.Value>
98
<ControlTemplate TargetType="controls:MetadataControl">
10-
<TextBlock x:Name="TextContainer" TextWrapping="Wrap" />
9+
<TextBlock x:Name="TextContainer"
10+
Style="{TemplateBinding TextBlockStyle}" />
1111
</ControlTemplate>
1212
</Setter.Value>
1313
</Setter>

Microsoft.Toolkit.Uwp.UI.Controls/MetadataControl/MetadataUnit.cs renamed to Microsoft.Toolkit.Uwp.UI.Controls/MetadataControl/MetadataItem.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
namespace Microsoft.Toolkit.Uwp.UI.Controls
88
{
99
/// <summary>
10-
/// A unit of metadata to display in <see cref="MetadataControl"/>.
10+
/// An item to display in <see cref="MetadataControl"/>.
1111
/// </summary>
12-
public struct MetadataUnit
12+
public struct MetadataItem
1313
{
1414
/// <summary>
15-
/// Gets or sets the label of the unit.
15+
/// Gets or sets the label of the item.
1616
/// </summary>
1717
public string Label { get; set; }
1818

1919
/// <summary>
20-
/// Gets or sets the automation name that will be set on the unit.
20+
/// Gets or sets the automation name that will be set on the item.
2121
/// If not set, <see cref="Label"/> will be used.
2222
/// </summary>
2323
public string AccessibleLabel { get; set; }
2424

2525
/// <summary>
26-
/// Gets or sets the command associated to the unit.
27-
/// If null, the unit will be displayed as a text field.
28-
/// If set, the unit will be displayed as an hyperlink.
26+
/// Gets or sets the command associated to the item.
27+
/// If null, the item will be displayed as a text field.
28+
/// If set, the item will be displayed as an hyperlink.
2929
/// </summary>
3030
public ICommand Command { get; set; }
3131

0 commit comments

Comments
 (0)