This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathIsNullOrEmptyStateTriggerPage.xaml.cs
More file actions
92 lines (76 loc) · 2.71 KB
/
IsNullOrEmptyStateTriggerPage.xaml.cs
File metadata and controls
92 lines (76 loc) · 2.71 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
83
84
85
86
87
88
89
90
91
92
// 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 Microsoft.Toolkit.Uwp.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
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 IsNullOrEmptyStateTriggerPage : Page, IXamlRenderListener
{
private Button _addButton;
private Button _removeButton;
private ListBox _listBox;
private Button _unselectButton;
private ListView _selectListView;
/// <summary>
/// Initializes a new instance of the <see cref="IsNullOrEmptyStateTriggerPage"/> class.
/// </summary>
public IsNullOrEmptyStateTriggerPage()
{
InitializeComponent();
}
public void OnXamlRendered(FrameworkElement control)
{
if (_addButton != null)
{
_addButton.Click -= this.AddButton_Click;
}
if (control.FindDescendant("AddButton") is Button btn)
{
_addButton = btn;
_addButton.Click += this.AddButton_Click;
}
if (_removeButton != null)
{
_removeButton.Click -= this.RemoveButton_Click;
}
if (control.FindDescendant("RemoveButton") is Button btn2)
{
_removeButton = btn2;
_removeButton.Click += this.RemoveButton_Click;
}
_listBox = control.FindDescendant("OurList") as ListBox;
_selectListView = control.FindDescendant("SelectList") as ListView;
if (control.FindDescendant("RemoveSelection") is Button btn3)
{
_unselectButton = btn3;
_unselectButton.Click += this.UnselectButton_Click;
}
}
private void AddButton_Click(object sender, RoutedEventArgs e)
{
if (_listBox != null)
{
_listBox.Items.Add("Item");
}
}
private void RemoveButton_Click(object sender, RoutedEventArgs e)
{
if (_listBox != null && _listBox.Items.Count > 0)
{
_listBox.Items.RemoveAt(0);
}
}
private void UnselectButton_Click(object sender, RoutedEventArgs e)
{
if(_selectListView != null && _selectListView.SelectedItem != null)
{
_selectListView.SelectedItem = null;
}
}
}
}