Free Study Guide for the Windows Presentation Framework exam 70-511: Items Control

  • For this blog entry, I did a bunch of links, scroll down to see the code and short video
  • If you are using a Windows Phone, there is an app that you can download to view the YouTube videos

 

A current example on MSDN, it’s a beauty!

Using the Item Controls:

ListBox Control Information:

 

 

XAML CODE (Sample code is attached to article)

 <Window x:Class="AttachedEvent.MainWindow"
        xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="322" Width="534">
    <Grid>  
        <TextBox Name="tb" Margin="42,215,12,12"
                 FontSize="28"
                 BorderThickness="5"
                 BorderBrush="Black">
            Select
        </TextBox>
        <ListBox Name="lb" 
                 Width="100" 
                 SelectionChanged="ShowSelection" 
                 SelectionMode="Single"
                 FontSize="28"
                 Margin="38,27,365,124"
                 BorderThickness="5"
                 BorderBrush="Black">
            <ListBoxItem>Boom</ListBoxItem>
            <ListBoxItem>Room</ListBoxItem>
            <ListBoxItem>Moon</ListBoxItem>
        </ListBox>
        
        <ListBox Name="lb2" Width="100" SelectionChanged="ShowSelection" 
                 SelectionMode="Single" 
                 Margin="163,28,249,124"
                 FontSize="28"
                 BorderThickness="5"
                 BorderBrush="Red">
            <ListBoxItem>Birds</ListBoxItem>
            <ListBoxItem>Cat</ListBoxItem>
            <ListBoxItem>Dog</ListBoxItem>
        </ListBox>
    </Grid>
</Window>

 

 

Code behind (Sample code is attached to article)

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AttachedEvent
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void ShowSelection(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem lbi = 
                ((sender as ListBox).SelectedItem 
                as ListBoxItem);
            tb.Text = 
                "   You selected " + 
                lbi.Content.ToString() + ".";
        }

List Control.zip