This project is read-only.

SelectedIndex in ElementFlow -Listbox

Jul 1, 2008 at 12:36 PM

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"
                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
 ItemsSource="{StaticResource TestDataSource}"
 ItemTemplate="{StaticResource TestDataTemplate}" MaxWidth="1024" MaxHeight="768">
<Controls:ElementFlow x:Name="ElementFlow"
 TiltAngle="{Binding Value, ElementName=_tiltAngleSlider}"
 ItemGap="{Binding Value, ElementName=_itemGapSlider}"
 FrontItemGap="{Binding Value, ElementName=_frontItemGapSlider}"
 PopoutDistance="{Binding Value, ElementName=_popoutDistanceSlider}"
<PerspectiveCamera FieldOfView="10"
  UpDirection="0,1,0" />

Jul 1, 2008 at 4: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.


Jul 2, 2008 at 12:27 AM
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.  ?

Jul 2, 2008 at 12:38 AM
This one of those cases where you may have to know a little more about the visual tree. IMHO.
Jul 2, 2008 at 12:47 AM

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....