Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

iam already searched listbox colr picker but how to add new color and name from panel and textbox as well as my given link image.
after searching my problem is not solved then i post here for code help.

how to add new color and name to listbox item like images,plz help me for code
for color i use panel and for name textbox1
how to remove
how to edit

http://www.mediafire.com/view/0jaudi438zm9fad/Untitled.jpg

plz share me the code
Posted
Updated 20-Sep-14 2:28am
v4
Comments
[no name] 20-Sep-14 8:32am    
In WPF, I think that you would need to create a DataTemplate and bind your list of color objects, whatever they are, to your listbox.
cadsolution 20-Sep-14 8:42am    
k,plz share me code
[no name] 20-Sep-14 9:28am    
Sorry, no. Writing your code is your job not mine.
cadsolution 22-Sep-14 1:23am    
plz anybody share me the code

1 solution

In WPF ,you will do this by using DataBinding ,First we have a DataModel Class which hold the number,name,colorname respectively..then add the following code

XAML Code:
XML
<ListBox>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel >
                        <TextBlock Text="{Binding Number}" Margin="2"></TextBlock>
                        <TextBlock Text="{Binding ColorName}" Margin="2"></TextBlock>
                        <StackPanel Background="{Binding color,Converter={StaticResource ColorConvertor}}" Margin="5"></StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

----------------------------------------------------------------------------------
.CS Code:
C#
public class MyColorConvertor :IValueConverter
  {

      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          string colorcode = value.ToString();

          if(colorcode=="Red")
              return new SolidColorBrush(Colors.Red);
          else if (colorcode == "Green")
              return new SolidColorBrush(Colors.Green);
          return new SolidColorBrush(Colors.White);
      }

      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          throw new NotImplementedException();
      }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900