How to use styles inside a DLL?

SRX

New member
Joined
Feb 3, 2018
Messages
1
Programming Experience
3-5
Hello everyone, this is my first post here, so here it is,

I'm making a DLL for me, to ease my job, because there are classes that I use in every project, so why should i duplicate them, when I can use one DLL to finish the job,

I also wanted to add some controls to it, buttons, so its like this:

I have created a button, and it works well, but I want to add a custom style to it, to disable the background highlighting when you are mouse over, now i have used this style before and works well, but in previous times, I would add the style to the app.xaml resources and then set the style to the button like:
C#:
Style="{StaticResource DisableBackgroundHighlight}"
but since the DLL does not have app.xaml, what should I do, how to add style to the control inside the DLL?
All I've found on google was, to reference the resources from the DLL to the app.xaml of the WPF app, but thats not what I want,
I tried this:

C#:
<Button x:Class="SRX.Windows.Controls.SRXButton"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:SRX.Windows.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="35" d:DesignWidth="100" Content="OK" Background="White" BorderBrush="Blue" Foreground="Blue" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave" Style="{StaticResource DisableBackgroundHighlight}">
    <Button.Resources>
        <Style x:Key="DisableBackgroundHighlight" TargetType="Button">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="0.8" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Button.Resources>
</Button>

but it doesnt work, it shows "The resource "DisableBackgroundHighlight" could not be resolved." altough it compiles but crashes on startup.
If I missed something in the problem explanation please ask me to resolve, thanks in advance.
 
Back
Top Bottom