[英]Moving merged XAML ResourceDictionaries to Generic.xaml causes error
我創建了兩個自定義控件,它們都繼承自System.Windows.Controls.Button。 一個叫做XLButton
,另一個叫XLBox
。 他們有相同的款式XAML /在兩個不同的模板ResourceDictionary
對象在兩個單獨的.xaml文件,和相同的代碼隱藏文件,除了“XLButton”出現在XLButton
文件,其中“XLBox”出現在XLBox
文件, 反之亦然 。
我創建了一個帶有兩行Grid
的簡單測試窗口。 我將ResourceDictionary
文件合並到該測試窗口的Window.Resources
中,並為每個自定義控件創建一個實例,在頂部一行,在底部一行。 這很好。 這是測試窗口的XAML:
<Window x:Class="ScratchPadWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExLuminaControls"
mc:Ignorable="d"
Title="ScratchPadWindow" Height="118" Width="145">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/XLBox.xaml" />
<ResourceDictionary Source="/Styles/XLButton.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<local:XLBox Content="Hi!"/>
<local:XLButton Grid.Row="1" Content="Yeah!"/>
</Grid>
</Window>
這樣很好。 但是,當我注釋掉ResourceDictionary.MergedDictionaries
部分並將其以原始形式復制到Themes\\Generic.xaml
,它看起來像這樣:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExLuminaControls"
mc:Ignorable="d">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/XLButton.xaml" />
<ResourceDictionary Source="/Styles/XLBox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
我收到與此行相關的“無法找到資源'styles / xlbutton.xaml'錯誤:
<local:XLBox Content="Hi!"/>
這對我來說沒有任何意義,但更令人困惑的是, 如果我在設計器中單擊“禁用項目代碼”,問題就消失了 。
我正在使用Blend 2017社區。
誰能幫我理解這一點?
謝謝!
這是路徑問題,在泛型中,像這樣使用
<ResourceDictionary Source="/AssemblyName;Component/Styles/XLButton.xaml" />
或必須加上“ ../../”
app.xaml如果沒有任何作用
[assembly:ThemeInfo(ResourceDictionaryLocation.None,//特定主題資源字典所在的// //(如果在頁面中找不到資源,則使用//,或應用程序資源字典)// ResourceDictionaryLocation.SourceAssembly //通用資源字典所在的位置位於//(如果在頁面,// app或任何主題特定的資源字典中找不到資源,則使用))]
<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Generic.xaml" /> ... </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
定義和風格
#region --------------------CONSTRUCTORS--------------------
static WaitSpin()
{
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(WaitSpin),
new FrameworkPropertyMetadata(typeof(WaitSpin)));
}
/// <summary>
/// LoadingAnimation constructor.
/// </summary>
public WaitSpin()
{
this.DefaultStyleKey = typeof(WaitSpin);
}
#endregion
<Style x:Key="{x:Type local:WaitSpin}" TargetType="{x:Type local:WaitSpin}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.