Tôi đang cố gắng tải kiểu WPF từ tệp khác thực sự từ Thư viện kiểm soát tùy chỉnh WPF nhưng tôi không tải được ở đây là giải pháp của tôi.Đang tải kiểu WPF từ Tệp tài nguyên
Các giải pháp bao gồm hai dự án
WpfTestControls của Loại WPF Thư viện Custom Control
WpfTestApp loại Thư viện ứng dụng WPF trong đó có tham chiếu đến WpfTestControls
MainWindow.xaml từ Thư viện ứng dụng WPF
<Window.Resources>
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="50px" Width="100px" Style="{DynamicResource TempStyle}"/>
</Grid>
Generic.xaml từ WPF Custom Control Library Thư viện
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfTestControls;component/TextBoxStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
TextBoxStyle.xaml từ WPF Custom Control
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
tập tin AssemblyInfo.cs My chứa sau
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries))]
Nhưng vẫn tôi đang thất bại trong việc tải các Style. Nếu tôi đang sử dụng không sử dụng Generic.xaml tất cả mọi thứ làm việc tốt ví dụ đoạn mã sau việc như mong đợi
<Window x:Class="WpfTestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="50px" Width="100px" Style="{StaticResource TempStyle}"/>
</Grid>
am i làm gì sai? Cảm ơn trước
Xin chào Có lẽ tôi đã viết sai nhưng Solution chứa hai dự án chỉ WpfTestControls của Loại WPF Custom Control Library và WpfTestApp của ứng dụng Wpf loại có tham chiếu hai WpfTestControls. – Robob
Đúng vậy, hãy xem bản chỉnh sửa của tôi ở trên ... –
Bạn nói đúng nhưng tôi hiểu nó phải làm việc với giải pháp trước đó. Đó là cách giải quyết mà tôi sẽ áp dụng cho bây giờ – Robob