UWP中的ReadOnly属性

Smi*_*rti 2 uwp

ReadOnly在UWP中找不到该属性.我可以ReadOnly在WPF中设置属性,如下所示,

[ReadOnly(true)]
public double? Salary
{
    get
    {
        return _salary;
    }
    set
    {
        _salary = value;
        RaisePropertyChanged("Salary");
    }
}
Run Code Online (Sandbox Code Playgroud)

ReadOnly在UWP不支持的属性?

Cle*_*ens 10

您可以将setter设为私有:

public double? Salary
{
    get { return _salary; }
    private set
    {
        _salary = value;
        RaisePropertyChanged("Salary");
    }
}
Run Code Online (Sandbox Code Playgroud)


Elv*_*SFT 5

System.ComponentModel.ReadOnlyAttributeUWP不支持.UWP的目标是.NET Core,而WPF则面向.NET Framework.

用于UWP应用程序的.NET不包括每种类型的所有成员.

对于System.ComponentModel.Net for UWP支持的命名空间下的所有类型,您可以引用UWP应用程序的System.ComponentModel命名空间.

ReadOnlyAttribute文档的"版本信息"部分.它在Windows Universal Platform中也不可用.