using resource dictionary in .NetCore Wpf user control Class libaray

essamce 621 Reputation points
2020-08-30T19:25:55.657+00:00

hi, i'm trying to use a .NetCore Wpf user Control Class libaray in some wpf application and it can't resolve the resource dictionary that used by a control i'm tying to use .

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
0 comments No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,626 Reputation points
    2020-08-31T03:48:27.527+00:00

    You can use a dictionary in the current project or another project to UserControl,here is the structure of my test demos for you to refer to:
    21471-capture.png

    The code for DictionaryB.xaml which included in namespace WpfControlLibrary2:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                        xmlns:local="clr-namespace:WpfControlLibrary2">  
        <Style x:Key="MyTxtStyleB" TargetType="TextBlock">  
            <Setter Property="FontSize" Value="20"></Setter>  
            <Setter Property="Foreground" Value="Yellow"></Setter>  
            <Setter Property="Background" Value="LightPink"></Setter>  
        </Style>  
    </ResourceDictionary>  
    

    The code for DictionaryA.xaml which included in namespace WpfControlLibrary:
    21467-capture1.png

    The code for UserControl1.xaml which included in namespace WpfControlLibrary:
    21453-capture2.png

    Use it the MainWindow.xaml which included in namespace DictionaryUse:

    <Grid>  
            <u:UserControl1></u:UserControl1>  
        </Grid>  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.