[英]How to access the resource via key defined in generic.xaml
目前我正在使用Generic.xaml
並在其中定義了一個自定義類實例。 像下面這樣:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TextPicker;component/Themes/FiltersTreeView.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
在FiltersTreeView.xaml
我定義了FiltersTreeView.xaml
定義 UI 類的一個實例。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:utils="clr-namespace:TextPicker.Utils"
xmlns:cmd="clr-namespace:TextPicker.Commands"
xmlns:cc="clr-namespace:TextPicker.CustomControls"
xmlns:dm="clr-namespace:TextPicker.Models">
<cc:ColorPiePopup x:Key="colorPiePopup"/>
....
<ResourceDictionary/>
現在,我嘗試使用Application.Current.FindResource
來查找它,但它總是返回null
。
那么如何從Generic.xaml
獲取定義的這個資源呢? 我的意思是使用代碼。
這個問題在這里回答:
您無法直接在您的應用程序中訪問 generic.xaml 中的資源。 [...] 因此,如果您想使用 generic.xaml 中的資源,則應將其添加為應用程序中的常規 ResourceDictionary
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.