-
-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathContextMenuItem.cs
More file actions
89 lines (77 loc) · 3.06 KB
/
ContextMenuItem.cs
File metadata and controls
89 lines (77 loc) · 3.06 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
namespace BootstrapBlazor.Components;
/// <summary>
/// <para lang="zh">ContextMenuItem 类</para>
/// <para lang="en">A type that represents a menu item in a <see cref="ContextMenu"/>.</para>
/// </summary>
public class ContextMenuItem : ComponentBase, IContextMenuItem, IDisposable
{
/// <summary>
/// <para lang="zh">获得/设置 显示文本</para>
/// <para lang="en">The text to display.</para>
/// </summary>
[Parameter]
public string? Text { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 图标</para>
/// <para lang="en">The CSS class name that represents an icon (if any)</para>
/// </summary>
/// <example>
/// Icon="fa-solid fa-bookmark"
/// </example>
[Parameter]
public string? Icon { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否被禁用 默认 false 优先级低于 <see cref="OnDisabledCallback"/></para>
/// <para lang="en">Flags whether the item is disabled. Default is <see langword="false"/>. It has a lower priority than <see cref="OnDisabledCallback"/>.</para>
/// </summary>
[Parameter]
public bool Disabled { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 是否被禁用回调方法 默认 null 优先级高于 <see cref="Disabled"/></para>
/// <para lang="en">Defines the callback to determine if the item is disabled. Default is <see langword="null" />. It has a higher priority than <see cref="Disabled"/>.</para>
/// </summary>
[Parameter]
public Func<ContextMenuItem, object?, bool>? OnDisabledCallback { get; set; }
/// <summary>
/// <para lang="zh">获得/设置 点击回调方法 默认 null</para>
/// <para lang="en">Defines the click callback. Default is <see langword="null" />.</para>
/// </summary>
[Parameter]
public Func<ContextMenuItem, object?, Task>? OnClick { get; set; }
[CascadingParameter]
[NotNull]
private ContextMenu? ContextMenu { get; set; }
/// <inheritdoc/>
protected override void OnInitialized()
{
base.OnInitialized();
ContextMenu.AddItem(this);
}
private bool disposedValue;
/// <summary>
/// <para lang="zh">释放资源方法</para>
/// <para lang="en">Method to release resources.</para>
/// </summary>
/// <param name="disposing"><para lang="zh">是否释放托管资源</para><para lang="en">Whether to release managed resources</para></param>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
ContextMenu.RemoveItem(this);
}
disposedValue = true;
}
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}