更快,更有效的颜色和尺寸选择方法 [英] Faster and Efficient Method to Choose Color and Size
问题描述
我需要向地图添加不同颜色的圆.我正在使用bing地图.在此之上,通过以下方法添加图层:
I need to add Circles of different colors to the map. I am using bing Maps. On top of this adding Layers by following method:
MapLayer RedLayer = new MapLayer();
MapLayer RedLayer = new MapLayer();
MapLayer BlueLayer =新的MapLayer();
MapLayer BlueLayer = new MapLayer();
MapLayer YellowLayer = new MapLayer();
MapLayer YellowLayer = new MapLayer();
MapLayer OrangeLayer = new MapLayer();
MapLayer OrangeLayer = new MapLayer();
AddLayer(MapLayer colorLayer,整数大小,SolidColorBrush颜色)
AddLayer(MapLayer colorLayer, int size, SolidColorBrush color)
此处最后一个参数颜色是根据时间范围设置的.例如:1990-1999年是红色,2000-2009年是蓝色.
Here the last argument color is set depending on time range. ex: 1990-1999 is Red, 2000-2009 Blue.
需要传递相同颜色的MapLayer.
The same color MapLayer needs to be passed.
大小需要通过输入列表中元素的数量来计算.如果inputSize> 10000 size = 90
The size needs to be calculated by number of elements in a input list. If inputSize > 10000 size = 90
5000< inputSize<< 10000,然后大小= 60. 最佳使用方法是什么?我不想使用switch或其他方法.
5000 < inputSize < 10000 then size =60. What is the best method to use ? I don't want to use switch or if else methods.
推荐答案
嗨wpf_xam1,
Hi wpf_xam1,
>>最佳使用方法是什么?我不想使用switch或其他方法.
如果您不想使用开关或其他方法.色彩转换器可能是您尝试的一种合适方法.
If you don't want to use a switch or if else methods. May be the Color Converter is a suitable way for you to try.
以下代码供您参考.
ColorConverterTest cctt = new ColorConverterTest();
Binding binding = new Binding("Item.Items");
binding.Converter = cctt;
textttxrich.SetBinding(TextBlock.ForegroundProperty, binding);
class ColorConverterTest : ValidationRule, IValueConverter
{
public override ValidationResult Validate(object value, CultureInfo culture)
{
return new ValidationResult(ConvertBack(value, typeof(string), null, culture) != DependencyProperty.UnsetValue,
"Please enter valid value");
}
public object Convert(object value, Type typeTarget, object param, CultureInfo culture)
{
if ((string)value == "1")
{
return "Green";
//return Colors.Green;
}
else if ((string)value == "2")
{
return "Yellow";
// return Colors.Yellow;
}
else if ((string)value == "3")
{
return "Red";
// return Colors.Red;
}
return "Red";
}
public object ConvertBack(object value, Type typeTarget, object param, CultureInfo culture)
{
if (value == null || value.ToString().Trim().Length == 0) return null;
string s = value.ToString();
if(s!="-1")
{
return s;
}
return DependencyProperty.UnsetValue;
}
}
如果您对必应地图有任何疑问,请访问必应地图论坛以获取适当的帮助.
If you have any question about bing Maps, please go to the bing Maps forum for getting suitable help.
Bing Maps WPF,WP7/8/8.1,Silverlight论坛:
https://social.msdn.microsoft.com/Forums/en-US/home? category = bingmaps
Bing Maps WPF, WP7/8/8.1, Silverlight forum:
https://social.msdn.microsoft.com/Forums/en-US/home?category=bingmaps
最好的问候,
吕汉楠
这篇关于更快,更有效的颜色和尺寸选择方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!