asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Problems with referencing resources.

01 Aug 2019, 18:20

I'm not sure if I'm just doing this wrong or there's a problem with Noesis. I defined two elements in a resource dictionary and I'm trying to reference one in the other. I shortened a lot of the actual XAML for this post.
<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Assets/Project/Views/Resources.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Grid x:Key="Inner" Height="60"/>
            <Grid x:Key="Outer">
                <ContentControl Content="{DynamicResource Inner}" />
            </Grid>
        </ResourceDictionary>
</UserControl.Resources>
    <ContentControl Margin="5" Content="{DynamicResource Outer}" />
</UserControl>
When importing this Unity seems to go in an infinite loop. If I understand correctly you'd need a DyanmicResource for the interdependencies in the Outer resource. Why would this cause an infinite loop?
 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: Problems with referencing resources.

06 Aug 2019, 20:19

Bump? It also freezes when (I think) I use the same element twice from a resource from the same user control.
<UserControl.Resources>
	<ResourceDictionary>
          	  <ResourceDictionary.MergedDictionaries>
        	     	   <ResourceDictionary Source="/Assets/Project/Views/Resources.xaml" />
          	  </ResourceDictionary.MergedDictionaries>
          	  <Grid x:Key="A"/>
         </ResourceDictionary>
 </UserControl.Resources>
<Border>
	<StackPanel>
		// Using it once is okay 
	 	<ContentControl Grid.Row="2" Content="{DynamicResource A}" />
	 	// Using it twice freezes Unity.
	 	<ContentControl Grid.Row="2" Content="{DynamicResource A}" />
	 </StackPanel>
</Border>
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Problems with referencing resources.

07 Aug 2019, 11:35

Hi and sorry for the late reply,

I was able to reproduce the freezing when using your last xaml, could you please report it in our bugtracker?

Anyway, defining UI elements as resources is not a good idea because a UI element can only have 1 single parent, so you wouldn't be able to assign it as content to different controls. What you want to do can be accomplished by using control templates:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <ControlTemplate x:Key="A" TargetType="Control">
            <Grid>
                <!-- define here the UI you want to replicate in several controls -->
            </Grid>
        </ControlTemplate>
    </Grid.Resources>
    <Border>
    	<StackPanel>
    	    <Control Grid.Row="2" Template="{StaticResource A}" />
    	    <Control Grid.Row="2" Template="{StaticResource A}" />
    	</StackPanel>
    </Border>
</Grid>
Hope this helps.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Problems with referencing resources.

07 Aug 2019, 13:39

Already created the report so you can track it: #1529
 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: Problems with referencing resources.

07 Aug 2019, 16:38

Awesome, thanks!

Who is online

Users browsing this forum: Google [Bot] and 1 guest