Здравствуйте. Как создать элемент управления, показывающий уровень введенного значения по цветовой шкале. Элемент управления должен содержать свойства зависимости: минимальное, максимальное и текущее значения. Как это сделать? Почему не работает данный код? | Код | public partial class MainWindow : Window { bool first = true;
public int Percent { get { return (int)GetValue(PercentProperty); } set { SetValue(PercentProperty, value); } }
public static readonly DependencyProperty PercentProperty = DependencyProperty.Register("Percent", typeof(int), typeof(MainWindow), new UIPropertyMetadata(0));
private void PushTheButton(int num) { if (first) { first = false; textBox1.Text = num.ToString(); return; } else textBox1.Text += num.ToString(); }
public MainWindow() { InitializeComponent(); }
private void Window_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.D0: if (first == true) { first = true; PushTheButton(Percent); } else if (first == false) { first = false; if (double.Parse(textBox1.Text) != 0) {
PushTheButton(Percent); } else { first = false; } } break; case Key.D1: if (first == true) { first = true; PushTheButton(Percent); } else if (first == false) { first = false; if (double.Parse(textBox1.Text) != 0) {
PushTheButton(Percent); } else { first = false; } } break; } }
}
|
| Код | <Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" KeyDown="Window_KeyDown"> <Grid> <TextBox Margin="191,27,195,262" IsReadOnly="True" Name="textBox1"> <TextBox.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Color="Green" Offset="0"></GradientStop> <GradientStop Color="Green" Offset="{Binding Percent, ElementName=root}"></GradientStop> <GradientStop Color="White" Offset="{Binding Percent, ElementName=root}"></GradientStop> <GradientStop Color="White" Offset="1"></GradientStop> </LinearGradientBrush> </TextBox.Background> </TextBox> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="210,204,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> </Grid> </Window>
|
|