我有一个双打列表,我想显示一个标签,其值很好。但是如果值接近最大值,我希望背景有红色阴影,如果接近最小值,我希望背景为蓝色;如果接近最小值,我希望背景为白色。
public partial class UserControlTest : Window
{
private double Highest;
private double Minimum;
private double Median;
public UserControlTest()
{
InitializeComponent();
DataSource dataSource = new DataSource();
Data dataSet = dataSource.GetData();
Bind(dataSet);
}
private void Bind(Data dataSet)
{
Highest = Convert.ToDouble(dataSet.Values.Max());
Minimum = Convert.ToDouble(dataSet.Values.Min());
Median = ((Highest - Minimum) / 2) + Minimum;
stk1.Children.Add(DisplayLabel(dataSet));
stk1.Children.Add(DisplayMax(dataSet));
stk1.Children.Add(DisplayMin(dataSet));
stk1.Children.Add(DisplayMed(dataSet));
}
private Label DisplayLabel(Data dataSet)
{
var label = new Label()
{
Content = String.Join(" , ", dataSet.Values),
Background = new SolidColorBrush(Colors.AliceBlue)
};
return label;
}
private Label DisplayMax(Data dataSet)
{
var maxlabel = new Label()
{
Background = new SolidColorBrush(Colors.Red)
};
return maxlabel;
}
private Label DisplayMin(Data dataSet)
{
var minlabel = new Label()
{
Background = new SolidColorBrush(Colors.Blue)
};
return minlabel;
}
private Label DisplayMed(Data dataSet)
{
var medlabel = new Label()
{
Content = Median,
Background = new SolidColorBrush(Colors.Pink)
};
return medlabel;
}
}
}
答案 0 :(得分:1)