-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathOnDeviceExtension.cs
More file actions
82 lines (71 loc) · 2.81 KB
/
OnDeviceExtension.cs
File metadata and controls
82 lines (71 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.System.Profile;
// TODO: For Uno we probably want to extend this with extra properties the light up on WASM/iOS/MacOS/Android/etc...?
// Or is this just XAML conditional Markup that Uno provides? https://platform.uno/docs/articles/platform-specific-xaml.html
// TODO: Do we want a Trigger version of this as well?
namespace CommunityToolkit.WinUI;
/// <summary>
/// The OnDevice markup extension allows you to customize UI appearance on a per-DeviceFamily basis.
/// </summary>
/// <example>
/// The next TextBlock will show the text 'Hello' on desktop computers, 'World' on Xbox and 'Hi' on all other devices
/// <code>
/// <TextBlock Text="{ui:OnDevice Default=Hi, Desktop=Hello, Xbox=World}"
/// xmlns:ui="using:CommunityToolkit.WinUI.UI" />
/// </code>
/// </example>
public partial class OnDeviceExtension : MarkupExtension
{
/// <summary>
/// Gets the current device family.
/// </summary>
private string DeviceFamily { get; } = AnalyticsInfo.VersionInfo.DeviceFamily;
/// <summary>
/// Gets or sets the default value for this property
/// </summary>
public object? Default { get; set; }
/// <summary>
/// Gets or sets a value for this property on Desktop
/// </summary>
public object? Desktop { get; set; }
/// <summary>
/// Gets or sets a value for this property on Holographic
/// </summary>
public object? Holographic { get; set; }
/// <summary>
/// Gets or sets a value for this property on IoT
/// </summary>
public object? IoT { get; set; }
/// <summary>
/// Gets or sets a value for this property on Team
/// </summary>
public object? Team { get; set; }
/// <summary>
/// Gets or sets a value for this property on Xbox
/// </summary>
public object? Xbox { get; set; }
/// <summary>
/// Returns an object value for the current DeviceFamily, Default is used when it is not set.
/// </summary>
/// <returns>The object value to set on the property where the extension is applied.</returns>
protected override object? ProvideValue()
{
switch (DeviceFamily)
{
case "Windows.Desktop":
return this.Desktop ?? this.Default;
case "Windows.Holographic":
return this.Holographic ?? this.Default;
case "Windows.IoT":
return this.IoT ?? this.Default;
case "Windows.Team":
return this.Team ?? this.Default;
case "Windows.Xbox":
return this.Xbox ?? this.Default;
default:
return this.Default;
}
}
}