2
比方說,我有一個名爲CarData的複雜屬性和一個簡單的bool AllowSubmit。 的XAML:wpf/silverlight綁定幫助
<Grid ..... DataContext={Binding CarData}>
...TextBoxes binded, working
....
last line in the grid:
<Button IsEnabled={Binding AllowSubmit}>
</Grid>
的問題是,AllowSubmit不綁定。我認爲這是因爲網格的DataContext綁定到CarData屬性,因爲如果我把按鈕放在網格外面,它會起作用。另外我想如果我通過將Buttons DataContext設置爲AllowSubmit「覆蓋」DataContext將有所幫助,但它不會工作。我知道這是一個新手問題,但要走的路是什麼?我很確定可以將Button綁定到與網格屬性不同的屬性。感謝您的幫助。
非常感謝您的幫助。 – rescueme
顯式設置DataContext屬性是一種不好的做法,除非您完全知道代碼將執行什麼操作。我同意CodeNaked解決方案。 –