locked
Trouble using external resources in inherited control RRS feed

  • Question

  • I have a control that inherits ItemsControl. The control uses several external resources, here is my XAML:

    <ItemsControl
    	x:Class="ScorePadWithItemsControl_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/BasicButton.xaml"/>
    				<ResourceDictionary Source="ms-appx:///UniversalAppExtras/NoDeleteTextBox.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" Margin="0,3">
    				<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}" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Stretch" IsTextPredictionEnabled="False" TextChanged="PlayerName_TextChanged" Tag="{Binding Index}" FontFamily="Global User Interface"/>
    				<Button Grid.Column="1" Style="{StaticResource BasicButton}" FontSize="32" Margin="3,0" 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" 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>

    And the declaration in my codebehind is:

    Public NotInheritable Class PlayerNames : Inherits ItemsControl

    As you can see, I am inheriting from ItemsControl and using several external resources in my XAML. However, the resources do not want to be accessed, and I receive the following error:

    Cannot find a Resource with the Name/Key NoDeleteTextBox

    Am I doing something wrong in ItemsControl.Resources? I have used these resources many times before in other controls and pages, so the only significant difference I can see between this and the other times I have used them is that this inherits from ItemsControl instead of UserControl or Page. Do I need to do something different because of this? Am I doing something else wrong? Any help would be appreciated. Thanks.


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

    Monday, October 13, 2014 1:01 AM

All replies

  • Nathan - post a reproduction app for me and we'll investigate.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 13, 2014 12:29 PM
    Moderator