Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Programming Windows Phone 7 : Items Controls - Changing the Panel

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
5/17/2011 4:46:54 PM
Internally, an ItemsControl uses an ItemsPresenter to display all the items. One of the essential elements used to display the items is a panel of some sort. By default, this is a StackPanel (or, with ListBox, a VirtualizingStackPanel) with a vertical orientation. A vertical StackPanel is such a natural choice for this job that you may not think about replacing it.

But you can replace it. It’s another template—but usually an extremely simple template—that you set to the ItemsPanel property defined by ItemsControl.

The HorizontalItemsControl project is much like the previous project. It has references and namespace declarations for Petzold.Silverlight.Phone and ElPasoHighSchool, and an identical Resources collection. The big difference is the use of a StackPanel with a horizontal orientation in the ItemsControl. The program also defines a rather different DataTemplate for each student and relies on a landscape orientation of the phone.

Because the ItemsControl is now displaying its items horizontally rather than vertically, the default behavior of ScrollViewer is all wrong. The ScrollViewer must be enabled for horizontal scrolling:

Example 1. Silverlight Project: HorizontalItemsControl File: MainPage.xaml (excerpt)
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

<ScrollViewer VerticalAlignment="Center"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled">
<ItemsControl ItemsSource="{Binding
Source={StaticResource sortedStudents}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource PhoneAccentBrush}"
BorderThickness="1"
CornerRadius="12"
Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<ContentControl Grid.Row="0"
HorizontalAlignment="Center"
Foreground="{Binding Sex,
Converter={StaticResource sexToBrushConverter}}">

<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding LastName}" />
<TextBlock Text=", " />
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text=", " />
<TextBlock Text="{Binding MiddleName}" />
</StackPanel>
</ContentControl>

<Image Grid.Row="1"
Source="{Binding PhotoFilename}"
Height="240"
Width="180"
Margin="6" />

<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<TextBlock Text="GPA=" />
<TextBlock Text="{Binding GradePointAverage}" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

</ItemsControl>
</ScrollViewer>
</Grid>


Towards the bottom of the ItemsControl markup you’ll see the ItemsPanel property set to an object of type ItemsPanelTemplate, which then encloses the Panel derivative you want to use.



Not every type of panel is suitable for an items control. Generally you’ll want to use a panel that organizes its children based on their order in its Children collection and not based on attached properties.

It is very common for programmers to create custom panels specifically for a ListBox or ItemsControl. Sometimes these panels take the form of circular organizations of children, or carousels. Toward the end of this chapter I’ll show you an example of a custom panel to display these students.

Other -----------------
- Programming Windows Phone 7 : Items Controls - Sorting
- Items Controls : Fun with DataTemplates
- Items Controls : Databases and Business Objects
- Items Controls : Binding to ItemsSource
- Items Controls : ListBox Selection
- Items Controls : Customizing Item Displays
- Items Controls and Visual Trees
- The Two Templates : Custom Controls
- The Two Templates : The Ever-Handy Thumb
- The Two Templates : Variations on the Slider
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer