0

I’m having a bit of trouble with resolving resources from an external assembly.

I have a Styles.xaml file in a project called Theme and I have a Default Button style which has been declared as follows:

    <Style TargetType="{x:Type Button}" x:Key="{x:Type Button}">
    <!--Setters here-->
    </Style>

And then in a separate WPF project (but in the same solution) I have the following in the app.xaml file:

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary
        Source="/Theme;component/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

Then in the main Window, I declare a default Button with no style attached to it like so:

    <Button Width="100" Height="100" />

In design view, the button appears to pick up the style from the Styles.xaml file, but when I build and run the project, the Button just defaults to the standard button style.

I have checked to see that the Theme.dll file has been copied across to the WPF build directory (and it has) so I don’t know why this is happening.

Interestingly, if I define the Button Style like this

    <Style TargetType="{x:Type Button}" x:Key="MyStyle">

And then reference it directly on the Button in the other project like this

    <Button Style={StaticResource MyStyle} Width="100" Height="100" />

It picks up the style in design view and works normally when the project is built and executed.

Any ideas? Any help would be great!

Kris

1 Answer 1

1

You may need to use a complete pack URI where you reference the XAML file, namely with siteoforigin if you don't reference embedded resources.

Sign up to request clarification or add additional context in comments.

1 Comment

This may be my lack of understanding but if I use a packuri like this: pack://siteoforigin:,,,/Theme;component/Styles.xaml I get the exception "Check that the directory exists in the specified location". The Theme assemby is in the root directory of the WPF app so i'm not sure why this isn't working. Thanks for your reply!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.