我的項目中定義了許多XAML Brush
對象。有些比較詳細。現在,他們都位於(EDIT)Brushes.xaml,在它自己的文件中定義爲ResourceDictionary中,像這樣:將畫筆的ResourceDictionary獲取到ItemsList中
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<LinearGradientBrush x:Key="FiveColorGradient" >
...with five gradient stops
</LinearGradientBrush>
<LinearGradientBrush x:Key="TwentyFourColorGradient" >
...with 24 gradient stops
</LinearGradientBrush>
<LinearGradientBrush x:Key="RedYellowGradient" >
...etc
</LinearGradientBrush>
</ResourceDictionary>
的問題是,如何獲取這些項目裝入ItemsList
控制,如ComboBox
?
(編輯)我希望利用XAML中的綁定語法,這將更容易維護。但是我沒有找到正確的語法。這是我試過到目前爲止:
<UserControl.Resources>
<ResourceDictionary >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Key="BrushesDictionary" Source="Brushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<ComboBox ItemsSource="{StaticResource BrushesDictionary}"/>
</Grid>
當然,這是踢回錯誤的,因爲你不能鍵指定給一個ResourceDictionary
,或什麼的。
(我試過找了一些想法,但都不是由未完全埋在內容聚合或歲月的塵埃......任何文件支持)
爲什麼你需要,因爲它們被定義爲加載它們在'ItemsList'資源在'App'下,它對你的'Combobox'也是可見的。只要嘗試使用'StaticResource'消耗它們,它就會解決。 –
顯然,我希望用戶能夠從列表中選擇其中的一個。 –
對不起,但你的問題似乎並不明顯。你想列出comboBox中的所有畫筆?如果是,你可以使用'App.Current.Resources'來訪問它們,並且使用'Keys'字典集合進行綁定。 –