SelectedIndex in ElementFlow -Listbox

Jul 1, 2008 at 11:36 AM
Hi

Great control!  I am having fun with incorporating this project into a much bigger project.  I am working with the Showcase project and made a change to elementFlow xaml example.  Instead of itemsControl, I changed it to listBox because I need to databind to the selectedItem in the list.  Since an ItemsControl does not support this, I have to use a listBox.  What now?  I can seem to get the  ElementFlow to populate with my databound collection and display properly, But when I change the selectedIndex of the listbox, nothing animates.  I tried to use the visual tree helper to get access to the elementFlow, but that didn't work.  I got a border, a grid and a rectangle, but no elementFlow.  I have no way of changing the selectedIndex of the elementFlow and have it animate the change in selection.  I know I am doing something fundamentally wrong...

here is the actual XAML:
<ListBox x:Name="_itemsControl"
 Grid.Row="0"
 Grid.Column="0"
 Grid.ColumnSpan="2"
                 Background="{x:Null}"
                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
 ItemsSource="{StaticResource TestDataSource}"
 ItemTemplate="{StaticResource TestDataTemplate}" MaxWidth="1024" MaxHeight="768">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Controls:ElementFlow x:Name="ElementFlow"
 Focusable="True"
 TiltAngle="{Binding Value, ElementName=_tiltAngleSlider}"
 ItemGap="{Binding Value, ElementName=_itemGapSlider}"
 FrontItemGap="{Binding Value, ElementName=_frontItemGapSlider}"
 PopoutDistance="{Binding Value, ElementName=_popoutDistanceSlider}"
 ElementWidth="1024"
 ElementHeight="1024"
 HasReflection="False"
 Background="Black">
<Controls:ElementFlow.Camera>
<PerspectiveCamera FieldOfView="10"
  Position="0,1,10"
  LookDirection="0,-1,-10"
  UpDirection="0,1,0" />
</Controls:ElementFlow.Camera>
</Controls:ElementFlow>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

Coordinator
Jul 1, 2008 at 3:16 PM
Here is something you can  try inside Window.Loaded:

            DependencyObject obj = VisualTreeHelper.GetChild(_itemsControl, 0);
            while ((obj is Controls.ElementFlow) == false)
            {
                obj = VisualTreeHelper.GetChild(obj, 0);
            }
            _elementFlow = obj as Controls.ElementFlow;

That should get you the reference. HTH.


Cheers!

Jul 1, 2008 at 11:27 PM
Thanks for the reply.  I did try that, since it was already in the example showcase source.  I get this error when trying this code in the Window1.xaml :

Specified index is out of range or child at index is null. Do not call this method if VisualChildrenCount returns zero, indicating that the Visual has no children. It breaks on this line : (obj = VisualTreeHelper.GetChild(obj, 0);) IThe obj references a System.Windows.Shapes.Rectangle. I am not sure why a rectangle is showing up.  But I guess I have to check the count and continue on in the loop.  ?

-Thanks
Steve 
Coordinator
Jul 1, 2008 at 11:38 PM
This one of those cases where you may have to know a little more about the visual tree. IMHO.
Jul 1, 2008 at 11:47 PM


pavanpodila wrote:
This one of those cases where you may have to know a little more about the visual tree. IMHO.


Agree! I was trying to use the list to get another control databound to it.  I can use the selected index and some other ways to get the current item and use that as the datacontext to the other control.  That should work.  

Thanks a ton....

-Steve