Bonjour,

j'essaye depuis ce matin d'utiliser un exemple obtenu sur le net. Il s'agit d'un drag and drop d'une ListBox à une autre. Je veux afficher le résultat de la fenêtre 2 lorsque je sélectionne un nom. Le problème c'est que je n'arrive pas ca plante. Merci de m'aider ou de me donne une direction.

Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<UserControl x:Class="Silverlight4.DragDropListBox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">
    <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Drag &amp; Drop ListBox Demo" FontSize="20" FontWeight="Bold" Foreground="Red" Margin="10"  Grid.Row="0"/>
        <StackPanel Orientation="Horizontal" Margin="10" Grid.Row="1">
 
            <toolKit:ListBoxDragDropTarget AllowDrop="True">
                <ListBox x:Name="customerListBoxMain" Height="200" Width="200" DisplayMemberPath="Name">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </toolKit:ListBoxDragDropTarget>
 
            <TextBlock Width="20" />
 
            <toolKit:ListBoxDragDropTarget AllowDrop="True">
                <ListBox Height="200" Width="200" DisplayMemberPath="Name" SelectionChanged="ListBox_SelectionChanged">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </toolKit:ListBoxDragDropTarget>
 
        </StackPanel>
    </Grid>
</UserControl>

Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
using System.Collections.ObjectModel;
 
namespace Silverlight4.DragDropListBox
{
    public class PersonDataProvider
    {
        public static ObservableCollection<Person> GetData()
        {
            return new ObservableCollection<Person>
                        {
                            new Person { Name = "Akash Sharma" },
                            new Person { Name = "Vinay Sen" },
                            new Person { Name = "Lalit Narayan" },
                            new Person { Name = "Madhumita Chatterjee" },
                            new Person { Name = "Priyanka Patil" },
                            new Person { Name = "Kumar Sanu" },
                            new Person { Name = "Victor Kapoor" }
 
                        };
        }
    }
}

Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
namespace Silverlight4.DragDropListBox
{
    public class Person
    {
        public string Name { get; set; }
    }
}

Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
using System.Windows.Controls;
using System.Windows;
 
namespace Silverlight4.DragDropListBox
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            customerListBoxMain.ItemsSource = PersonDataProvider.GetData();
        }
 
        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem lib = ((sender as ListBox).SelectedItem as ListBoxItem);
            string libelle = lib.ToString();
            //MessageBox.Show("Personne : " + libelle);
        }
    }
}