2
是否有可能爲多個控件創建一個Dependency屬性,而無需訴諸每個子類的子類?Silverlight:如何將一個Dependency屬性添加到多個控件?
我想過使用附加屬性,但是據我瞭解,它們只嵌套一層。
我想這樣的事情成爲可能:
<!-- MyDataGrid implements the new Attached Properties SourceData and TargetData -->
<MyDataGrid>
<StackPanel>
<TextBox MyDataGrid.SourceData="{Binding Somewhere}" MyDataGrid.TargetData="{Binding Somewhere}" />
</StackPanel>
<CheckBox MyDataGrid.SourceData="{Binding Somewhere}" MyDataGrid.TargetData="{Binding Somewhere}" />
</MyDataGrid>
這不會起作用,因爲附加屬性不會在TextBox中找到,因爲它是MyDataGrid沒有直系後裔。
背景是,我嘗試自動將舊的類似Xaml的Gui語法轉換爲真正的Xaml,並且使用舊系統可以爲更改的數據設置不同的源和目標。現在我正在尋找一種Xaml解決方案,它不涉及每個控件的子類化。
在此先感謝。
哦,我的。當然,這在我的代碼中完全是無稽之談。非常感謝。 :) – Amenti 2011-04-08 11:10:23