Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Complex Listbox
Message
De
07/11/2009 11:10:22
 
 
À
07/11/2009 06:33:45
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Divers
Thread ID:
01433632
Message ID:
01433676
Vues:
40
Couldn't resist trying binding to the XML. This is self contained
<Window x:Class="junk.Window6"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window6" Height="300" Width="300" >
    <Window.Resources>
        <XmlDataProvider x:Key="XDP" XPath="Parents">
            <x:XData>
                <Parents xmlns="">
                    <Parent Name="Parent1">
                        <Child Title="Child1" Print="Y" Active="Y" PrintPath="C:\Print" LogPath="C:\Log" />
                        <Child Title="Child2" Print="Y" Active="Y" PrintPath="C:\Print" LogPath="C:\Log" />
                    </Parent>
                    <Parent Name="Parent2">
                        <Child Title="Child1" Print="Y" Active="Y" PrintPath="C:\Print" LogPath="C:\Log" />
                    </Parent>
                    <Parent Name="Parent3">
                        <Child Title="Child3" Print="Y" Active="Y" PrintPath="C:\Print" LogPath="C:\Log" />
                    </Parent>
                </Parents>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>
 
    <ListBox x:Name="LB" ItemsSource="{Binding Source={StaticResource XDP},XPath=Parent}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Expander Header="{Binding XPath=@Name}">
                    <ListBox ItemsSource="{Binding XPath=Child}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderThickness="2" BorderBrush="Blue" Margin="4">
                                    <StackPanel Orientation="Vertical">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock>Title: </TextBlock>
                                            <TextBlock Text="{Binding XPath=@Title}"/>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Print: "/>
                                            <TextBlock Text="{Binding XPath=@Print}"/>
                                        </StackPanel>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Expander>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Window>
>Thanks. I'll see what I can do with this, but it might be a while. I head to Germany on Tuesday.
>
>>I see you've considered a treeview and that would probably be the simplest - but a ListView approach shouldn't be too difficult either. Make the Parent Collection the ItemsSource to the Listbox and use a DataTemplate for the Children that includes the Expander and another ListBox - binding this one to the CurrentItem.Children of the outer ListBox. Adding/Deleting and Moving should be achievable by just manipulating the underlying objects (I'm assuming that you will derive objects from the XML?)
>>HTH,
>>Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform