0
可能只是一些愚蠢的錯誤,但我似乎無法找到它。問題是:編譯器說屬性「IsMarried」沒有可訪問的setter,我不知道「accessible」意味着什麼,因爲那裏肯定有一個setter。XAML(WPF)屬性沒有可訪問的setter來布爾值
XAML:
<Window x:Class="BindingTests.MainWindow"
...
xmlns:cnsmr="clr-namespace:BindingTests;assembly=BindingTests">
<Window.Resources>
<cnsmr:CustomerViewModel x:Key="CustomerViewModel" ... IsMarried="true"/>
</Window.Resources>
Customer.cs:
namespace BindingTests
{
class Customer
{
...
public string Married { get; set; }
...
}
}
CustomerViewModel.cs
namespace BindingTests
{
class CustomerViewModel
{
private Customer obj = new Customer();
...
public bool IsMarried
{
get
{
if (obj.Married == "Married")
{
return true;
}
else
{
return false;
}
}
set
{
if (value)
{
obj.Married = "Married";
}
else
{
obj.Married = "Not Married";
}
}
}
...
只是爲了澄清,我不能看到這個二傳手從其他的不同之處現有setter,它不會產生錯誤: 也CustomerViewModel.cs:
public string TxtCustomerName
{
get { return obj.CustomerName; }
set { obj.CustomerName = value; }
}
看起來很好,清潔和重建?我注意到我的項目中的XAML有時會有點滑稽 –
@AppPack,不幸的是,沒有幫助。 –