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