![](/img/trans.png)
[英]WPF force xaml to re-fetch the property's value although the property's setter didn't change
[英]XAML (WPF) property has no accessible setter to bool value
可能只是一些愚蠢的錯誤,但我似乎找不到它。 問題是:編譯器說屬性“ IsMarried”沒有可訪問的設置器 ,我也不知道“可訪問”的含義,因為那里肯定有一個設置器。
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";
}
}
}
...
為了澄清起見,我看不到此設置器與另一個現有設置器的區別,后者沒有出現任何錯誤:還有CustomerViewModel.cs:
public string TxtCustomerName
{
get { return obj.CustomerName; }
set { obj.CustomerName = value; }
}
我知道這是一個愚蠢的錯誤。 問題是XAML中的此字符串:
xmlns:cnsmr="clr-namespace:BindingTests;assembly=BindingTests"
我是從一些教程中得到的,只是盲目復制。 刪除了“; assembly = BindingTests”部分,現在一切正常。 現在XAML看起來像這樣:
xmlns:cnsmr="clr-namespace:BindingTests"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.