2
votes

I created my resource dictionary and can access styles in it, but how (If possible) would I reference an entire control from it?

Here's the resourcedictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="MainWindowStyle" TargetType="Window">
        <Setter Property="Background" Value="Transparent"></Setter> 
        <!--Can access this-->
    </Style>

    <Window x:Key="CustomWindow" Background="Transparent">
        <!--Want to access this-->
    </Window>

</ResourceDictionary>

Here's the main window xaml file:

<Window x:Class="MyNamespace.MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="640" Width="960" >
        <!--setting Style={StaticResource MainWindowStyle} adds the style but I want this window to be replaced by the one in the resourcedictionary-->
    <Grid>

    </Grid>
</Window>

So I basically want to replace the window in the xaml file with the one created in the resource dictionary.

1

1 Answers

1
votes

You can certainly host something like a UserControl within another control.

E.g. a ContentControl

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Window x:Key="CustomUserControl" Background="Transparent">
    <!--Want to access this-->
</Window>

</ResourceDictionary>

Then:

<ContentControl Content="{StaticResource ResourceKey=CustomUserControl}" />

I suspect that's not quite what you're after, but it's not clear what you may/may not have within the Window that's of interest.