添加和删除并编辑新颜色到列表框 [英] add and remove and edit new color to listbox
问题描述
iam已经搜索了listbox colr选择器,但是如何从面板和文本框以及我给定的链接图像中添加新的颜色和名称。
搜索我的问题后没有解决然后我在这里发布代码帮助。
如何添加新的颜色和名称到列表框项目,如图像,PLZ帮我代码
颜色我使用面板和名称textbox1
如何删除
如何编辑
http://www.mediafire.com/view/0jaudi438zm9fad/Untitled.jpg
plz分享代码
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
推荐答案
在WPF中,您将使用DataBinding执行此操作,首先我们有一个DataModel类,它分别包含数字,名称,颜色名称。然后添加以下代码
XAML代码:
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:
<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代码:
----------------------------------------------------------------------------------
.CS Code:
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();
}
}
这篇关于添加和删除并编辑新颜色到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!