locked
Preloading External Resources and/or Styles

    Question

  • I have several resources located in other projects that I want to use in another project. However, when I try to do this, I get errors during runtime when I navigate to page containing the control that uses the resources (which are Styles). If I remove the Styles from the control (by getting rid of the Style attribute), everything is fine (except that my control does not look the way I want). Based on everything I could find, this is because the control is attempting to use the resources before they are loaded. However, I have been unable to find a way to explicitly load the resources beforehand. Is there any way to force my control to load the resources before attempting to use them? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Saturday, February 7, 2015 9:09 PM

All replies

  • Hi,

    How do you use the external resource? Please share a reproduce sample for us. As far as I know, In windows store app,you have to use ms-appx for Resource dictionaries in dlls. The Build Action should be Page.

    Example:

    If you have a dll named "CustomControl" with a ResourceDictionary named "Styles.xaml", the App.xaml should contain

         
    <ResourceDictionary>
                 <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="ms-appx:///CustomControls/Styles.xaml"/>
                 </ResourceDictionary.MergedDictionaries>
             </ResourceDictionary>

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.


    Monday, February 9, 2015 6:31 AM
  • I use the external resource in a control that is in a Portable Class Library, which means that there is no App.xaml. The control is in a Portable Class Library because I am creating a Universal App. The control actually inherits from ItemsControl rather than UserControl. Is this causing a problem? Here is the XAML for the control:
    <ItemsControl
    	x:Class="GolfScoresUnivAppTest_Common.PlayerNames"
    	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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:app="using:UniversalAppExtras" mc:Ignorable="d">
    	<ItemsControl.Resources>
    		<ResourceDictionary>
    			<ResourceDictionary.MergedDictionaries>
    				<ResourceDictionary Source="ms-appx:///UniversalAppExtras/NoDeleteTextBox.xaml"/>
    				<ResourceDictionary Source="ms-appx:///UniversalAppExtras/BasicButton.xaml"/>
    				<ResourceDictionary>
    					<app:IsNullOrWhiteSpaceConverter x:Key="IsNullOrWhiteSpace"/>
    					<app:HideValueOpacityConverter x:Key="HideValueOpacity"/>
    				</ResourceDictionary>
    			</ResourceDictionary.MergedDictionaries>
    		</ResourceDictionary>
    	</ItemsControl.Resources>
    	<ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
    	<ItemsControl.ItemTemplate>
    		<DataTemplate>
    			<Grid x:Name="grdPlayerTemplate" Loaded="grdPlayerTemplate_Loaded">
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="Auto"/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
    				<TextBox Grid.Column="0" Style="{StaticResource NoDeleteTextBox}" FontSize="32" Margin="0,3" Padding="3,-6" Text="{Binding PlayerName}" Tag="{Binding Index}" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Stretch" IsTextPredictionEnabled="False" TextChanged="PlayerName_TextChanged" Loaded="PlayerName_Loaded" GotFocus="PlayerName_GotFocus"/>
    				<Button Grid.Column="1" Style="{StaticResource BasicButton}" FontSize="32" Margin="3,1.5" Padding="0,-2,1,-1" Content="&#xE10A;" Tag="{Binding Index}" FontFamily="Segoe UI Symbol" IsEnabled="{Binding Children[0].Text,ElementName=grdPlayerTemplate,Converter={StaticResource IsNullOrWhiteSpace},ConverterParameter=NOT}" Click="DeletePlayer_Click"/>
    				<Button Grid.Column="2" Style="{StaticResource BasicButton}" FontSize="32" Margin="0,1.5" Padding="8,1,8,2" Content="Move Up" Tag="{Binding Index}" IsEnabled="{Binding Children[0].Text,ElementName=grdPlayerTemplate,Converter={StaticResource IsNullOrWhiteSpace},ConverterParameter=NOT}" Opacity="{Binding Index,Converter={StaticResource HideValueOpacity}}" Click="MoveUp_Click"/>
    			</Grid>
    		</DataTemplate>
    	</ItemsControl.ItemTemplate>
    </ItemsControl>
    Is there something wrong with this code that is causing it to not load? Is there something I need to add? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, February 9, 2015 4:49 PM