Click here to Skip to main content
13,409,971 members (37,383 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

I have a WrapPanel control that's within a template that's within a custom control, I need to change it's orientation depending on a certain criteria being met.

<pan:Panorama x:Name="panMainContent" Grid.Column="0" Grid.Row="1" Margin="0,3"

              Foreground="Black" UseSnapBackScrolling="False" 

              VerticalAlignment="Top" IsManipulationEnabled="False"


              <ListBox x:Name="lbCategories" BorderBrush="{x:Null}" 



                         removed="{x:Null}" IsManipulationEnabled="True" 




                                 <WrapPanel Name="wp" IsItemsHost="True"

                                            Width="Auto" Orientation="Vertical"

                                            Height="{Binding ElementName=gridContent,Path=ActualHeight}"



                                        IsManipulationEnabled="True" ItemHeight="{Binding ElementName=tt, Path=ActualHeight}" >
                                <uc:TouchTile x:Name="tt" Click="Tile_Click"





               ProcessLaunchStartedEvent="tt_ProcessLaunchStartedEvent" Width="180">

I am having trouble referencing the "wp" WrapPanel from the code behind, as it doesn't appear.

I'm assuming once I have the reference to this control I can literally just:

if (criteria is met)
   //change orientation to horizontal
   //change orientation to vertical

Has anyone got any idea how I can refer to this control in the code? Many Thanks!
Posted 16-Oct-12 1:39am
Updated 16-Oct-12 22:45pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I do not know why you want to do this from code behind. You can, but you can also do it in the viewmodel with binding. Here is your solution:

if (criteria is met)
  wp.Orientation = Orientation.Horizontal;
  wp.Orientation = Orientation.Vertical;
MitchG92_24 17-Oct-12 3:14am
I know how to do the actual change of orientation. But it won't allow me to reference the WrapPanel. I feel this is because it is in a template so isnt instantiated until runtime. I've tried finding the control by name way about it but no luck.
It is needed on the code behind because as the items within the WrapPanel change, it needs to switch orientation depending on that.
Clifford Nelson 17-Oct-12 12:31pm
You did not have this information in the question. You still should have been able to do the same thing with Binding since the information would have been available when the control needed it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I found how to do it whilst reading this article:[^]

All it takes is declaring a WrapPanel variable at the start of your code:

private WrapPanel wp = new WrapPanel();

And then hooking into the WrapPanel that already exists in your XAML, and accessing the Loaded event and casting the WrapPanel to tge variable just created:

private void wp_Loaded(object sender, RoutedEventArgs e)
    wp = sender as WrapPanel;

Alot easier than I thought!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180221.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100