Hello all, I'm working with my first org chart and it's not behaving. I have a tree of nodes that have a template:
<DataTemplate x:Key="ScreenDataTemplate">
<StackPanel Orientation="Vertical" Width="Auto" Height="Auto" Background="#533090">
<ListBox ItemsSource="{Binding DerivedScreens}" BorderThickness="1" BorderBrush="Black" Margin="0"
Background="#F0E91B" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="text" Loaded="SubScreenLoaded" Text="{Binding Name}" FontWeight="Bold" FontSize="16" Foreground="#533090" Margin="0" >
<TextBlock.Resources>
<Storyboard x:Name="fadeOutStory">
<DoubleAnimation Storyboard.TargetName="text"
Storyboard.TargetProperty="Opacity" From="1.0" To="0.25" Duration="0:0:1" />
<ColorAnimation Duration="0:0:01" To="#BEBEBE"
Storyboard.TargetName="text"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
/>
</Storyboard>
<Storyboard x:Name="fadeInStory">
Storyboard.TargetProperty="Opacity" From="0.25" To="1.0" Duration="0:0:1" />
<ColorAnimation Duration="0:0:01" To="#533090"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" />
</TextBlock.Resources>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
Based on another input, I run the story for a textblock. However, if I zoom in on the tree and the node happens to go off the page, the story effects are removed when I zoom back out. I've spent hours with the LayoutUpdated() method for the TextBlock and have not come up with a good solution. In the code behind, I am keeping all of the textblocks in a dictionary when they are loaded so that I can iterate through them later. I can post more code as needed.
More testing has found that the TextBlock is recreated whenever it is scrolled off the page. That took me longer than it should have to figure out, but truly frustrating.
So if I can't keep a reference to a textblock, what would be the best way to get to all of them if they are created in a template for each node? Is there a way to get the contents of an OrgChartNode if it is created based on a template?
Just an update that I've changed my code behind to keep a reference to the TextBlock every time Loaded is called, but it seems like I should be able to get a reference to it from the OrgChartNode
Hello jgold,
It has been awhile since you made this post and if you still need any assistance on this matter I will be glad to help. I have been researching your scenario and I have created a small test sample based on your description , still I am not able to reproduce the issue on my side. Would you please take a look at the attached sample and modify it in order to represent the issue.
Thanks in advance.