I am trying to Drag and Drop from 1 list to another. I tried the code below. It Drags and Drops properly, but does not change the color of text Dropped to another List. (I want the color of text dropped in next to change, so that it is figurable to know which text was dropped (suppose Blue color)).
I have MainPage.xaml like this:
<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" xmlns:local="clr-namespace:Silverlight4.DragDropListBox"><UserControl.Resources><local:StyleFunctionConverter x:Key="StyleFunctionConverter"/></UserControl.Resources><Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center"><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions><TextBlock Text="Drag & 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" Style="{Binding IsInGroup, Converter={StaticResource StyleFunctionConverter}}"><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" Style="{Binding IsInGroup, Converter={StaticResource StyleFunctionConverter}}"><ListBox.ItemsPanel><ItemsPanelTemplate><StackPanel Orientation="Vertical"/></ItemsPanelTemplate></ListBox.ItemsPanel></ListBox></toolKit:ListBoxDragDropTarget></StackPanel></Grid></UserControl>
And MainPage.Xaml.cs class is:
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); customerListBoxMain.ItemsSource = PersonDataProvider.GetData(); } }
And class PersonDataProvider.cs is :
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" }, new Person { Name = "Shymal Sen" }, new Person { Name = "Alan D'Souza" }, new Person { Name = "Kamal Saha" }, new Person { Name = "Alex Chan" }, new Person { Name = "Rohit Sharma" }, new Person { Name = "Dipti Sen" }, new Person { Name = "Dinesh Sharma" }, new Person { Name = "Kamal Kapoor" }, new Person { Name = "Raj Kapoor" }, new Person { Name = "Deepa Karmakar" }, new Person { Name = "Sarmishtha Chakrobarty" }, new Person { Name = "Pranab Kumar Debnath" }, new Person { Name = "Hiral Grover" }, new Person { Name = "Munmun Patel" }, new Person { Name = "Santosh Kumar Sen" }, new Person { Name = "Sandeep Debnath" } }; } }
And Person.cs (Model is)
public class Person { public string Name { get; set; } }
And Styles.xaml (resource Dictionary)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Style x:Key="ListBoxTextNormalItem" TargetType="TextBlock"><Setter Property="Foreground"><Setter.Value><SolidColorBrush Color='Blue' /></Setter.Value></Setter></Style></ResourceDictionary>And App.xaml is:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Silverlight4.DragDropListBox.App"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="Styles.xaml"></ResourceDictionary></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources></Application> And StyleFunctionConverter.cs is: public class StyleFunctionConverter : IValueConverter { public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) { if (value == null) return null; bool isInGroup = (bool)value; if (isInGroup) return Application.Current.Resources["ListBoxTextNormalItem"]; else return Application.Current.Resources["ListBoxTextChangeItem"]; } public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) { return null; } }How do I make the color of Dropped text to
<SolidColorBrush
Color='Blue' />
?