Tôi đang sử dụng RadControls của Telerik cho WPF với kiểu dáng ẩn. Phong cách sau đây được định nghĩa trong Themes/Windows8/Telerik.Windows.Controls.RibbonView.xaml
:Kiểu dựa trên StaticResource được xác định trước đó không được tìm thấy trong thời gian chạy
<Style TargetType="telerikRibbonView:RadRibbonView" x:Key="RadRibbonViewStyle">
...
</Style>
phong cách riêng của tôi và những người mặc định Telerik được sáp nhập như thế này trong lắp ráp Lib.Windows.Controls
trong thư mục Themes
:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Windows8/Telerik.Windows.Controls.RibbonView.xaml" />
<ResourceDictionary Source="MyTheme/TelerikCustomizations.xaml" />
<ResourceDictionary>
<!-- avoid optimization -->
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Và trong TelerikCustomizations.xaml
tôi xác định như sau (trống, cho mục đích thử nghiệm) kiểu:
<Style x:Key="MyThemeRadRibbonViewStyle" TargetType="{x:Type telerik:RadRibbonView}" BasedOn="{StaticResource ResourceKey=RadRibbonViewStyle}" />
Kết quả nào trong ngoại lệ sau khi chạy:
'Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.' Line number '4' and line position '42'. {"Cannot find resource named 'RadRibbonViewStyle'. Resource names are case sensitive."}
nào dẫn tôi đến những điều khoản sửa lỗi sau đây trong MyView.xaml.cs:
public ShellView()
{
var baseStyle = FindResource("RadRibbonViewStyle");
var inherited = FindResource("MyThemeRadRibbonViewStyle");
InitializeComponent();
}
Bây giờ vấn đề là: Trường hợp ngoại lệ được ném vào thứ hai FindResource
gọi. Với cùng một thông điệp. Tuy nhiên, RadRibbonViewStyle
được tìm thấy rõ ràng trong dòng đầu tiên của hàm tạo.
Nếu quan trọng, từ điển đã hợp nhất thực sự được hợp nhất trong App.xaml lần thứ hai.
Tôi chắc chắn rằng tôi thiếu điều gì đó hiển nhiên, nhưng tôi không thể hiểu được điều gì.
App.xaml
<Application x:Class="TestClient.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Views/ShellView.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Lib.Windows.Controls;component/Themes/MyTheme.xaml" />
<ResourceDictionary>
<!-- added to avoid optimization -->
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
App.xaml.cs
không ghi đè các nhà xây dựng. Trong thực tế nó không làm bất cứ điều gì.
Cập nhật
Nếu tôi kết hợp các từ điển Telerik trong TelerikCustomizations.xaml
thay vì sáp nhập chúng vào thêm một từ điển (MyTheme.xaml
), ngoại trừ biến mất.
Tuy nhiên, tôi vẫn muốn biết tại sao điều này xảy ra.
Tôi nghĩ TelerikCustomizations.xaml không thể tìm thấy RadRibbonViewStyle trong BasedOn = "{StaticResource ResourceKey = RadRibbonViewStyle}" – ethicallogics
Vâng, nhưng tại sao? Chủ đề/Windows8/Telerik.Windows.Controls.RibbonView.xaml được hợp nhất ngay trước TelerikCustomizations.xaml. – cguedel
Bạn không còn thiếu 'Chủ đề' từ nguồn từ điển tài nguyên đầu tiên? –