我有,現在我的WPF應用程序還挺可怕的問題...自定義用戶控件「的IsEnabled」數據綁定不工作
我已經使用編輯器部件的細節自定義用戶控件。它應該從未啓用開始,並在用戶選擇要編輯的組件時立即啓用。
問題是:IsEnabled屬性甚至沒有改變。
這裏是我的代碼:
<my:UcComponentEditor Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsEnabled="{Binding EditorEnabled}"
DataContext="{Binding VmComponent}" />
EditorEnabled是在我的視圖模型(VmComponent)的屬性,並且默認爲false,當用戶選擇了一個組件或創建一個
只是爲了成爲真正的記錄,在我的ViewModel:
private Boolean _editorEnabled = false;
public Boolean EditorEnabled
{
get { return _editorEnabled; }
set
{
_editorEnabled = value;
OnPropertyChanged("EditorEnabled");
}
}
當我嘗試啓動我的應用程序時,UserControl啓動...啓用。 我在所有地方添加了斷點,EditorEnabled從一開始就是錯誤的。
我也做了一個可怕的愚蠢的事情,試圖找出發生了什麼:我創建了一個轉換器(如此有用 - 將布爾轉換爲布爾 - 呃),把一個斷點,並... ...代碼永遠不會到達。
<my:UcComponentEditor Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsEnabled="{Binding EditorEnabled, Converter={StaticResource BoolConverter}}"
DataContext="{Binding VmComponent}" />
這可能意味着屬性isEnabled從不設置,因爲轉換器永遠不會到達。
您是否在那裏看到任何問題?我開始在WPF工作大約一個星期前,因此我可能錯過了一些重要的...
非常感謝您的寶貴時間:-)
斷點停在'_editorEnabled = value;'? – 2011-03-17 12:05:08
正確創建了VmComponent?據我所知,該綁定不會初始化一個新的對象。 – Harry 2011-03-17 12:18:56
@Fun Mun Pieng:是的,它通過了setter @Harry:是的,VmComponent被創建,並且適合所有其他需求,只有這個不工作 – Damascus 2011-03-17 12:53:02