Using UserControl.Resources

17,237

Make sure that the build action of your Resource.xaml is set to Page.

Furthermore see, if your relative URI "Resources\Resource.xaml" is correct.

As an example for the URI syntax suppose your UserControl NavigationControl is living in a namespace called Client and the namespace Client is contained in a namespace called App. If App would contain a namespace Resources and your Resource.xaml would reside in this namespace then the correct URI would be ../Resources/Resource.xaml.

Share:
17,237
anevil
Author by

anevil

Updated on June 04, 2022

Comments

  • anevil
    anevil almost 2 years

    I've got some problem while using UserControl.Resources. I keep encounter error message "The file 'Resources\Resource.xaml' is not part of the project or its 'Build Action' property is not set to 'Resource'.

    I've search through the forums but looks like I've done exactly what has been stated in the sample. somehow the error still there and the style embedded in the resource is failed to be applied into my controls. Below are my codes :

    <UserControl x:Class="Client.NavigationControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:local="clr-namespace:Client"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top"
                 d:DesignHeight="59"
                 d:DesignWidth="349"
                 mc:Ignorable="d">
    
    <UserControl.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Resources\Resource.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
     </UserControl.Resources>
    
    <Grid Name="grid1"
              Width="341"
              Height="54"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch">
    
    
     <Button Name="button2"
                    Width="97"
                    Height="35"
                    Margin="106,10,0,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    Command="{Binding ButtonResponseSection}"
                    CommandParameter="ResponseSection"
                    Content="ResponseSection"
                    Style="{DynamicResource GlassButton}" />
    
    
        </Grid>
    </UserControl>
    

    Please help :-(..

  • anevil
    anevil over 12 years
    thanks for the answer!I've put the reference to the resource within App.xaml and now its works! thanks a lot!