BindableObject.SetValue 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
SetValue(BindableProperty, Object) |
设置指定的可绑定属性的值。 |
SetValue(BindablePropertyKey, Object) |
设置指定的可绑定属性的值。 |
SetValue(BindableProperty, Object)
设置指定的可绑定属性的值。
public:
void SetValue(Microsoft::Maui::Controls::BindableProperty ^ property, System::Object ^ value);
public void SetValue (Microsoft.Maui.Controls.BindableProperty property, object value);
member this.SetValue : Microsoft.Maui.Controls.BindableProperty * obj -> unit
Public Sub SetValue (property As BindableProperty, value As Object)
参数
- property
- BindableProperty
要为其赋值的可绑定属性。
- value
- Object
要设置的值。
例外
当 property
为 null
时,将引发此异常。
注解
如果 property
为只读,则不会发生任何操作。
适用于
SetValue(BindablePropertyKey, Object)
设置指定的可绑定属性的值。
public:
void SetValue(Microsoft::Maui::Controls::BindablePropertyKey ^ propertyKey, System::Object ^ value);
public void SetValue (Microsoft.Maui.Controls.BindablePropertyKey propertyKey, object value);
member this.SetValue : Microsoft.Maui.Controls.BindablePropertyKey * obj -> unit
Public Sub SetValue (propertyKey As BindablePropertyKey, value As Object)
参数
- propertyKey
- BindablePropertyKey
标识要向其分配值的可绑定属性的键。
- value
- Object
要设置的值。
例外
当 propertyKey
为 null
时,将引发此异常。
当 标识 propertyKey
的可绑定属性为只读时引发。
注解
此方法 和 BindablePropertyKey 可用于在有限的写入访问权限下实现 BindableProperties。 写入访问权限仅限于 BindablePropertyKey 的范围。
以下示例演示如何声明具有“内部”写入访问权限的 BindableProperty。
class MyBindable : BindableObject
{
internal static readonly BindablePropertyKey MyPropertyKey =
BindableProperty.CreateReadOnly<MyBindable, string> (w => w.My, default(string));
public static readonly BindableProperty MyProperty = MyPropertyKey.BindableProperty;
public string My {
get { return (string)GetValue (MyProperty); }
internal set { SetValue (MyPropertyKey, value); }
}
}
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈