Skip to content

Commit 7fbbe61

Browse files
committed
Merge remote-tracking branch 'upstream/main' into win-app-sdk-1.8
2 parents d515235 + 97e87eb commit 7fbbe61

13 files changed

+395
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ You can customize the appearance and behavior of the `TableView` by modifying it
207207
6. TableViewTemplateColumn
208208
7. TableViewTimeColumn
209209
8. TableViewDateColumn
210+
9. TableViewHyperlinkColumn
210211

211212
## Contributing
212213

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Data;
4+
5+
namespace WinUI.TableView;
6+
7+
/// <summary>
8+
/// Represents a column in a TableView that displays a HyperlinkButton.
9+
/// </summary>
10+
[StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(HyperlinkButton))]
11+
[StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(TextBox))]
12+
#if WINDOWS
13+
[WinRT.GeneratedBindableCustomProperty]
14+
#endif
15+
public partial class TableViewHyperlinkColumn : TableViewTextColumn
16+
{
17+
/// <summary>
18+
/// Generates a HyperlinkButton element for the cell.
19+
/// </summary>
20+
/// <param name="cell">The cell for which the element is generated.</param>
21+
/// <param name="dataItem">The data item associated with the cell.</param>
22+
/// <returns>A HyperlinkButton element.</returns>
23+
public override FrameworkElement GenerateElement(TableViewCell cell, object? dataItem)
24+
{
25+
var hyperlinkButton = new HyperlinkButton
26+
{
27+
Margin = new Thickness(2, 0, 2, 0),
28+
HorizontalAlignment = HorizontalAlignment.Stretch,
29+
HorizontalContentAlignment = HorizontalAlignment.Left
30+
};
31+
32+
// Bind NavigateUri to the main Binding property
33+
hyperlinkButton.SetBinding(HyperlinkButton.NavigateUriProperty, Binding);
34+
35+
// Bind Content to ContentBinding if set, otherwise use the NavigateUri
36+
var contentBinding = ContentBinding ?? Binding;
37+
hyperlinkButton.SetBinding(ContentControl.ContentProperty, contentBinding);
38+
39+
return hyperlinkButton;
40+
}
41+
42+
/// <summary>
43+
/// Gets or sets the binding for the hyperlink content.
44+
/// If not set, the NavigateUri binding will be used for the content.
45+
/// </summary>
46+
public Binding? ContentBinding { get; set; }
47+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.ComponentModel;
2+
3+
namespace WinUI.TableView;
4+
5+
/// <summary>
6+
/// Provides data for the CellDoubleTapped event.
7+
/// </summary>
8+
public partial class TableViewCellDoubleTappedEventArgs : HandledEventArgs
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the TableViewCellDoubleTappedEventArgs class.
12+
/// </summary>
13+
/// <param name="slot">The slot of the cell.</param>
14+
/// <param name="cell">The TableViewCell associated with the event.</param>
15+
/// <param name="item">The item associated with the cell.</param>
16+
public TableViewCellDoubleTappedEventArgs(TableViewCellSlot slot, TableViewCell cell, object? item)
17+
{
18+
Slot = slot;
19+
Cell = cell;
20+
Item = item;
21+
}
22+
23+
/// <summary>
24+
/// Gets the slot of the cell.
25+
/// </summary>
26+
public TableViewCellSlot Slot { get; }
27+
28+
/// <summary>
29+
/// Gets the TableViewCell associated with the event.
30+
/// </summary>
31+
public TableViewCell Cell { get; }
32+
33+
/// <summary>
34+
/// Gets the item associated with the cell.
35+
/// </summary>
36+
public object? Item { get; }
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.ComponentModel;
2+
3+
namespace WinUI.TableView;
4+
5+
/// <summary>
6+
/// Provides data for the RowDoubleTapped event.
7+
/// </summary>
8+
public partial class TableViewRowDoubleTappedEventArgs : HandledEventArgs
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the TableViewRowDoubleTappedEventArgs class.
12+
/// </summary>
13+
/// <param name="index">The index of the row.</param>
14+
/// <param name="row">The TableViewRow associated with the event.</param>
15+
/// <param name="item">The row associated with double tap/click.</param>
16+
public TableViewRowDoubleTappedEventArgs(int index, TableViewRow row, object? item)
17+
{
18+
Index = index;
19+
Row = row;
20+
Item = item;
21+
}
22+
23+
/// <summary>
24+
/// Gets the index of the row.
25+
/// </summary>
26+
public int Index { get; }
27+
28+
/// <summary>
29+
/// Gets the TableViewRow associated with the event.
30+
/// </summary>
31+
public TableViewRow Row { get; }
32+
33+
/// <summary>
34+
/// Gets the item associated with the row.
35+
/// </summary>
36+
public object? Item { get; }
37+
}

src/Extensions/ObjectExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ private static Expression BuildPropertyPathExpressionTree(ParameterExpression pa
134134

135135
private static Expression EnsureObjectCompatibleResult(Expression expression)
136136
{
137-
// Only convert to object if the expression type is not already assignable to object without boxing
138-
if (expression.Type.IsValueType
139-
&& !expression.Type.IsNullableType() // e.g. int? is considered a ValueType, but also nullable, which means it can be converted to object without boxing
140-
)
137+
// Ensure the final expression can be used in an object-returning lambda (boxing value types, including nullable value types)
138+
if (expression.Type.IsValueType)
141139
return Expression.Convert(expression, typeof(object));
142140
return expression;
143141
}

src/Extensions/TypeExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,12 @@ internal static bool IsEnumerableType(this Type enumerableType)
173173
{
174174
return FindGenericType(typeof(IEnumerable<>), enumerableType) != null;
175175
}
176+
177+
/// <summary>
178+
/// Determines whether the specified type is a Uri.
179+
/// </summary>
180+
internal static bool IsUri(this Type type)
181+
{
182+
return type == typeof(Uri);
183+
}
176184
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<data name="DatePickerPlaceholder" xml:space="preserve">
121+
<value>Vyber dátum</value>
122+
</data>
123+
<data name="BlankFilterValue" xml:space="preserve">
124+
<value>(Prázdne)</value>
125+
</data>
126+
<data name="Cancel" xml:space="preserve">
127+
<value>Zrušiť</value>
128+
</data>
129+
<data name="ClearFilter" xml:space="preserve">
130+
<value>Zrušiť Filter</value>
131+
</data>
132+
<data name="Ok" xml:space="preserve">
133+
<value>Ok</value>
134+
</data>
135+
<data name="SelectAllParenthesized" xml:space="preserve">
136+
<value>(Vyber všetko)</value>
137+
</data>
138+
<data name="SortAscending" xml:space="preserve">
139+
<value>Zoraď Vzostupne</value>
140+
</data>
141+
<data name="ClearSorting" xml:space="preserve">
142+
<value>Zrušiť Zoradenie</value>
143+
</data>
144+
<data name="SortDescending" xml:space="preserve">
145+
<value>Zoraď Zostupne</value>
146+
</data>
147+
<data name="TimePickerPlaceholder" xml:space="preserve">
148+
<value>Vyber čas</value>
149+
</data>
150+
<data name="CopyCommandDescription" xml:space="preserve">
151+
<value>Skopíruj obsah riadku.</value>
152+
</data>
153+
<data name="CopyWithHeaders" xml:space="preserve">
154+
<value>Skopíruj s hlavičkou</value>
155+
</data>
156+
<data name="CopyWithHeadersCommandDescription" xml:space="preserve">
157+
<value>Skopíruj obsah riadku s hlavičkou do schránky.</value>
158+
</data>
159+
<data name="DeselectAll" xml:space="preserve">
160+
<value>Odznač všetko</value>
161+
</data>
162+
<data name="DeselectAllCommandDescription" xml:space="preserve">
163+
<value>Odznač všetky riadky.</value>
164+
</data>
165+
<data name="ExportAll" xml:space="preserve">
166+
<value>Exportuj všetko do CSV</value>
167+
</data>
168+
<data name="ExportSelected" xml:space="preserve">
169+
<value>Exportuj vybrané do CSV</value>
170+
</data>
171+
<data name="SelectAllCommandDescription" xml:space="preserve">
172+
<value>Vyber všetky riadky.</value>
173+
</data>
174+
<data name="SelectAll" xml:space="preserve">
175+
<value>Vyber všetko</value>
176+
</data>
177+
<data name="SearchBoxPlaceholder" xml:space="preserve">
178+
<value>Hľadaj...</value>
179+
</data>
180+
<data name="Copy" xml:space="preserve">
181+
<value>Kopírovať</value>
182+
</data>
183+
</root>

src/TableView.Events.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@ protected virtual void OnRowContextFlyoutOpening(TableViewRowContextFlyoutEventA
9292
RowContextFlyoutOpening?.Invoke(this, args);
9393
}
9494

95+
/// <summary>
96+
/// Event triggered when a row is double-tapped.
97+
/// </summary>
98+
public event EventHandler<TableViewRowDoubleTappedEventArgs>? RowDoubleTapped;
99+
100+
/// <summary>
101+
/// Called before the <see cref="RowDoubleTapped"/> event occurs.
102+
/// </summary>
103+
/// <param name="args">The event data.</param>
104+
protected internal virtual void OnRowDoubleTapped(TableViewRowDoubleTappedEventArgs args)
105+
{
106+
RowDoubleTapped?.Invoke(this, args);
107+
}
108+
109+
/// <summary>
110+
/// Event triggered when a cell is double-tapped.
111+
/// </summary>
112+
public event EventHandler<TableViewCellDoubleTappedEventArgs>? CellDoubleTapped;
113+
114+
/// <summary>
115+
/// Called before the <see cref="CellDoubleTapped"/> event occurs.
116+
/// </summary>
117+
/// <param name="args">The event data.</param>
118+
protected internal virtual void OnCellDoubleTapped(TableViewCellDoubleTappedEventArgs args)
119+
{
120+
CellDoubleTapped?.Invoke(this, args);
121+
}
122+
95123
/// <summary>
96124
/// Event triggered when the cell context flyout is opening.
97125
/// </summary>

src/TableView.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@ private static TableViewBoundColumn GetTableViewColumnFromType(string? propertyN
650650
{
651651
column = new TableViewCheckBoxColumn();
652652
}
653+
else if(type.IsUri())
654+
{
655+
column = new TableViewHyperlinkColumn();
656+
}
653657

654658
column.Binding = binding;
655659

0 commit comments

Comments
 (0)