mercredi 3 août 2011


ItemsControl Name="ItemsList"  BorderThickness="0"
                       ItemsSource="{Binding ElementName=ThisControl, Path=NotifyContent}"
                       ItemTemplate="{StaticResource ItemsTemplate}" >

remplir une list avec un contenu extern
{Binding ElementName=ThisControl, Path=NotifyContent}
elementname=l'objet source de l'information  comme le id dans html
le path=la propriete voulu

    <TextBlock Width="248" Height="24" Text="Colors:" 
    <ListBox x:Name="lbColor" Width="248" Height="56">
        <ListBoxItem Content="Blue"/>
        <ListBoxItem Content="Green"/>
        <ListBoxItem Content="Yellow"/>
        <ListBoxItem Content="Red"/>
        <ListBoxItem Content="Purple"/>
        <ListBoxItem Content="Orange"/>
    <TextBlock Width="248" Height="24" Text="You selected color:" />
    <TextBlock Width="248" Height="24">
            <Binding ElementName="lbColor" Path="SelectedItem.Content"/>

The code listed in Figure 1 can be modified slightly to use a shorthand syntax for data binding. For example, let's replace the TextBlock's <Binding> tag with the following code snippet:
<TextBlock Width="248" Height="24" 
    Text="{Binding ElementName=lbColor, 
    Path=SelectedItem.Content}" />

Aucun commentaire:

Enregistrer un commentaire

Nombre total de pages vues