Browse Source
- added NumericUpDown to ICSharpCode.Core.Presentation git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5475 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
13 changed files with 741 additions and 139 deletions
@ -1,110 +0,0 @@
@@ -1,110 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
public class IDEOptionPanel : XmlFormsOptionPanel |
||||
{ |
||||
readonly static string uiLanguageProperty = "CoreProperties.UILanguage"; |
||||
ListView listView = new ListView(); |
||||
Label newCulture = new Label(); |
||||
|
||||
|
||||
|
||||
string SelectedCulture { |
||||
get { |
||||
if (listView.SelectedItems.Count > 0) { |
||||
return listView.SelectedItems[0].SubItems[1].Text; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
string SelectedCountry { |
||||
get { |
||||
if (listView.SelectedItems.Count > 0) { |
||||
return listView.SelectedItems[0].Text; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override bool StorePanelContents() |
||||
{ |
||||
if (SelectedCulture != null) { |
||||
PropertyService.Set(uiLanguageProperty, SelectedCulture); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void ChangeCulture(object sender, EventArgs e) |
||||
{ |
||||
newCulture.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.UILanguageSetToLabel") + " " + SelectedCountry; |
||||
} |
||||
|
||||
string GetCulture(string languageCode) |
||||
{ |
||||
foreach (Language language in LanguageService.Languages) { |
||||
if (languageCode.StartsWith(language.Code)) { |
||||
return language.Name; |
||||
} |
||||
} |
||||
return "English"; |
||||
} |
||||
|
||||
public IDEOptionPanel()// : base(panelName)
|
||||
{ |
||||
listView.Location = new Point(8, 8); |
||||
listView.Size = new Size(136, 200); |
||||
listView.LargeImageList = LanguageService.LanguageImageList; |
||||
listView.ItemActivate += new EventHandler(ChangeCulture); |
||||
listView.Sorting = SortOrder.Ascending; |
||||
listView.Activation = ItemActivation.OneClick; |
||||
listView.Anchor = (System.Windows.Forms.AnchorStyles.Top | |
||||
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)); |
||||
listView.MultiSelect = false; |
||||
|
||||
foreach (Language language in LanguageService.Languages) { |
||||
listView.Items.Add(new ListViewItem(new string[] {language.Name, language.Code}, language.ImageIndex)); |
||||
} |
||||
|
||||
this.Controls.Add(listView); |
||||
|
||||
Label culture = new Label(); |
||||
culture.Location = new Point(8, 220); |
||||
culture.Size = new Size(350, 16); |
||||
culture.Anchor = (System.Windows.Forms.AnchorStyles.Top | |
||||
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)); |
||||
|
||||
Dock = DockStyle.Fill; |
||||
|
||||
culture.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel") + " " + GetCulture(PropertyService.Get(uiLanguageProperty, "en")); |
||||
this.Controls.Add(culture); |
||||
|
||||
Label descr = new Label(); |
||||
descr.Location = new Point(8, 280); |
||||
descr.Size = new Size(390, 50); |
||||
descr.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.DescriptionText"); |
||||
descr.Anchor = (System.Windows.Forms.AnchorStyles.Top | |
||||
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)); |
||||
|
||||
this.Controls.Add(descr); |
||||
|
||||
newCulture.Location = new Point(8, 240); |
||||
newCulture.Size = new Size(360, 50); |
||||
newCulture.Anchor = (System.Windows.Forms.AnchorStyles.Top | |
||||
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)); |
||||
this.Controls.Add(newCulture); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
<gui:OptionPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels" |
||||
x:Name="window" |
||||
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.SelectCulturePanel"> |
||||
<gui:OptionPanel.Resources> |
||||
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}"> |
||||
<Setter Property="BorderBrush" Value="Black" /> |
||||
<Setter Property="BorderThickness" Value="0.5" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate> |
||||
<Border Name="bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}"> |
||||
<ScrollViewer Margin="{TemplateBinding Padding}"> |
||||
<WrapPanel ItemWidth="96" ItemHeight="64" IsItemsHost="True" MinWidth="50" Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"></WrapPanel> |
||||
</ScrollViewer> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> |
||||
<Setter Property="Padding" Value="3" /> |
||||
<Setter Property="HorizontalContentAlignment" Value="Center" /> |
||||
<Setter Property="ContentTemplate"> |
||||
<Setter.Value> |
||||
<DataTemplate> |
||||
<Grid HorizontalAlignment="Center" VerticalAlignment="Top"> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
<Image HorizontalAlignment="Center" Width="32"> |
||||
<Image.Source> |
||||
<BitmapImage UriSource="{Binding ImagePath}" DecodePixelWidth="32" DecodePixelHeight="24" /> |
||||
</Image.Source> |
||||
</Image> |
||||
<TextBlock Grid.Row="1" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" Text="{Binding Name}" /> |
||||
</Grid> |
||||
</DataTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ImageView},ResourceId=ImageView}" /> |
||||
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ImageView},ResourceId=ImageViewItem}" /> |
||||
</gui:OptionPanel.Resources> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
<ListView x:Name="listView" Margin="5,0" Height="200" SelectedItem="{sd:OptionBinding local:SelectCulturePanel.CurrentLanguage}"> |
||||
<ListView.View> |
||||
<local:ImageView /> |
||||
</ListView.View> |
||||
</ListView> |
||||
<TextBlock Grid.Row="1" Margin="5,0"> |
||||
<TextBlock.Text> |
||||
<MultiBinding StringFormat="{}{0} {1}"> |
||||
<sd:LocalizeExtension Key="Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel" /> |
||||
<Binding Path="SelectedItem.Name" ElementName="listView" /> |
||||
</MultiBinding> |
||||
</TextBlock.Text> |
||||
</TextBlock> |
||||
<TextBlock Grid.Row="2" Margin="5,0"> |
||||
<TextBlock.Text> |
||||
<MultiBinding StringFormat="{}{0} {1}"> |
||||
<sd:LocalizeExtension Key="Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel" /> |
||||
<Binding Path="CurrentLanguage.Name" ElementName="window" /> |
||||
</MultiBinding> |
||||
</TextBlock.Text> |
||||
</TextBlock> |
||||
<TextBlock Grid.Row="3" TextWrapping="Wrap" Text="{sd:Localize Dialog.Options.IDEOptions.SelectCulture.DescriptionText}" Margin="5" /> |
||||
</Grid> |
||||
</gui:OptionPanel> |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
public partial class SelectCulturePanel : OptionPanel |
||||
{ |
||||
public SelectCulturePanel() |
||||
{ |
||||
InitializeComponent(); |
||||
listView.ItemsSource = LanguageService.Languages; |
||||
} |
||||
|
||||
static readonly string langPropName = "CoreProperties.UILanguage"; |
||||
|
||||
public static Language CurrentLanguage { |
||||
get { return GetCulture(PropertyService.Get(langPropName, "en")); } |
||||
set { PropertyService.Set(langPropName, value.Code); } |
||||
} |
||||
|
||||
static Language GetCulture(string languageCode) |
||||
{ |
||||
return LanguageService.Languages.FirstOrDefault(x => x.Code.StartsWith(languageCode)) |
||||
?? LanguageService.Languages.First(x => x.Code.StartsWith("en")); |
||||
} |
||||
} |
||||
|
||||
public class ImageView : ViewBase |
||||
{ |
||||
protected override object DefaultStyleKey |
||||
{ |
||||
get { return new ComponentResourceKey(GetType(), "ImageView"); } |
||||
} |
||||
|
||||
protected override object ItemContainerDefaultStyleKey |
||||
{ |
||||
get { return new ComponentResourceKey(GetType(), "ImageViewItem"); } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
public delegate void DragHandler(DragListener drag); |
||||
|
||||
public class DragListener |
||||
{ |
||||
static DragListener() |
||||
{ |
||||
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput); |
||||
} |
||||
|
||||
public DragListener(IInputElement target) |
||||
{ |
||||
Target = target; |
||||
|
||||
Target.PreviewMouseLeftButtonDown += Target_MouseDown; |
||||
Target.PreviewMouseMove += Target_MouseMove; |
||||
Target.PreviewMouseLeftButtonUp += Target_MouseUp; |
||||
} |
||||
|
||||
static DragListener CurrentListener; |
||||
|
||||
static void PostProcessInput(object sender, ProcessInputEventArgs e) |
||||
{ |
||||
if (CurrentListener != null) { |
||||
var a = e.StagingItem.Input as KeyEventArgs; |
||||
if (a != null && a.Key == Key.Escape) { |
||||
Mouse.Capture(null); |
||||
CurrentListener.IsDown = false; |
||||
CurrentListener.IsCanceled = true; |
||||
CurrentListener.Complete(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Target_MouseDown(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
StartPoint = Mouse.GetPosition(null); |
||||
CurrentPoint = StartPoint; |
||||
DeltaDelta = new Vector(); |
||||
IsDown = true; |
||||
IsCanceled = false; |
||||
} |
||||
|
||||
void Target_MouseMove(object sender, MouseEventArgs e) |
||||
{ |
||||
if (IsDown) { |
||||
DeltaDelta = e.GetPosition(null) - CurrentPoint; |
||||
CurrentPoint += DeltaDelta; |
||||
|
||||
if (!IsActive) { |
||||
if (Math.Abs(Delta.X) >= SystemParameters.MinimumHorizontalDragDistance || |
||||
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance) { |
||||
IsActive = true; |
||||
CurrentListener = this; |
||||
|
||||
if (Started != null) { |
||||
Started(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (IsActive && Changed != null) { |
||||
Changed(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Target_MouseUp(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
IsDown = false; |
||||
if (IsActive) { |
||||
Complete(); |
||||
} |
||||
} |
||||
|
||||
void Complete() |
||||
{ |
||||
IsActive = false; |
||||
CurrentListener = null; |
||||
|
||||
if (Completed != null) { |
||||
Completed(this); |
||||
} |
||||
} |
||||
|
||||
public event DragHandler Started; |
||||
public event DragHandler Changed; |
||||
public event DragHandler Completed; |
||||
|
||||
public IInputElement Target { get; private set; } |
||||
public Point StartPoint { get; private set; } |
||||
public Point CurrentPoint { get; private set; } |
||||
public Vector DeltaDelta { get; private set; } |
||||
public bool IsActive { get; private set; } |
||||
public bool IsDown { get; private set; } |
||||
public bool IsCanceled { get; private set; } |
||||
|
||||
public Vector Delta { |
||||
get { return CurrentPoint - StartPoint; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,302 @@
@@ -0,0 +1,302 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Media.Imaging; |
||||
using System.Windows.Navigation; |
||||
using System.Windows.Shapes; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Globalization; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
public class NumericUpDown : Control |
||||
{ |
||||
static NumericUpDown() |
||||
{ |
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(typeof(NumericUpDown))); |
||||
} |
||||
|
||||
TextBox textBox; |
||||
DragRepeatButton upButton; |
||||
DragRepeatButton downButton; |
||||
|
||||
public static readonly DependencyProperty DecimalPlacesProperty = |
||||
DependencyProperty.Register("DecimalPlaces", typeof(int), typeof(NumericUpDown)); |
||||
|
||||
public int DecimalPlaces { |
||||
get { return (int)GetValue(DecimalPlacesProperty); } |
||||
set { SetValue(DecimalPlacesProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty MinimumProperty = |
||||
DependencyProperty.Register("Minimum", typeof(double), typeof(NumericUpDown)); |
||||
|
||||
public double Minimum { |
||||
get { return (double)GetValue(MinimumProperty); } |
||||
set { SetValue(MinimumProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty MaximumProperty = |
||||
DependencyProperty.Register("Maximum", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(100.0)); |
||||
|
||||
public double Maximum { |
||||
get { return (double)GetValue(MaximumProperty); } |
||||
set { SetValue(MaximumProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty ValueProperty = |
||||
DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); |
||||
|
||||
public double Value { |
||||
get { return (double)GetValue(ValueProperty); } |
||||
set { SetValue(ValueProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty SmallChangeProperty = |
||||
DependencyProperty.Register("SmallChange", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(1.0)); |
||||
|
||||
public double SmallChange { |
||||
get { return (double)GetValue(SmallChangeProperty); } |
||||
set { SetValue(SmallChangeProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty LargeChangeProperty = |
||||
DependencyProperty.Register("LargeChange", typeof(double), typeof(NumericUpDown), |
||||
new FrameworkPropertyMetadata(10.0)); |
||||
|
||||
public double LargeChange { |
||||
get { return (double)GetValue(LargeChangeProperty); } |
||||
set { SetValue(LargeChangeProperty, value); } |
||||
} |
||||
|
||||
bool IsDragging { |
||||
get { |
||||
return upButton.IsDragging; |
||||
} |
||||
set { |
||||
upButton.IsDragging = value; downButton.IsDragging = value; |
||||
} |
||||
} |
||||
|
||||
public override void OnApplyTemplate() |
||||
{ |
||||
base.OnApplyTemplate(); |
||||
|
||||
upButton = (DragRepeatButton)Template.FindName("PART_UpButton", this); |
||||
downButton = (DragRepeatButton)Template.FindName("PART_DownButton", this); |
||||
textBox = (TextBox)Template.FindName("PART_TextBox", this); |
||||
|
||||
upButton.Click += new RoutedEventHandler(upButton_Click); |
||||
downButton.Click += new RoutedEventHandler(downButton_Click); |
||||
|
||||
var upDrag = new DragListener(upButton); |
||||
var downDrag = new DragListener(downButton); |
||||
|
||||
upDrag.Started += drag_Started; |
||||
upDrag.Changed += drag_Changed; |
||||
upDrag.Completed += drag_Completed; |
||||
|
||||
downDrag.Started += drag_Started; |
||||
downDrag.Changed += drag_Changed; |
||||
downDrag.Completed += drag_Completed; |
||||
|
||||
Print(); |
||||
} |
||||
|
||||
void drag_Started(DragListener drag) |
||||
{ |
||||
OnDragStarted(); |
||||
} |
||||
|
||||
void drag_Changed(DragListener drag) |
||||
{ |
||||
IsDragging = true; |
||||
MoveValue(-drag.DeltaDelta.Y * SmallChange); |
||||
} |
||||
|
||||
void drag_Completed(DragListener drag) |
||||
{ |
||||
IsDragging = false; |
||||
OnDragCompleted(); |
||||
} |
||||
|
||||
void downButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (!IsDragging) SmallDown(); |
||||
} |
||||
|
||||
void upButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (!IsDragging) SmallUp(); |
||||
} |
||||
|
||||
protected virtual void OnDragStarted() |
||||
{ |
||||
} |
||||
|
||||
protected virtual void OnDragCompleted() |
||||
{ |
||||
} |
||||
|
||||
public void SmallUp() |
||||
{ |
||||
MoveValue(SmallChange); |
||||
} |
||||
|
||||
public void SmallDown() |
||||
{ |
||||
MoveValue(-SmallChange); |
||||
} |
||||
|
||||
public void LargeUp() |
||||
{ |
||||
MoveValue(LargeChange); |
||||
} |
||||
|
||||
public void LargeDown() |
||||
{ |
||||
MoveValue(-LargeChange); |
||||
} |
||||
|
||||
void MoveValue(double delta) |
||||
{ |
||||
double result; |
||||
if (double.IsNaN(Value) || double.IsInfinity(Value)) { |
||||
SetValue(delta); |
||||
} |
||||
else if (double.TryParse(textBox.Text, out result)) { |
||||
SetValue(result + delta); |
||||
} |
||||
else { |
||||
SetValue(Value + delta); |
||||
} |
||||
} |
||||
|
||||
void Print() |
||||
{ |
||||
if (textBox != null) { |
||||
textBox.Text = Value.ToString("F" + DecimalPlaces); |
||||
textBox.CaretIndex = int.MaxValue; |
||||
} |
||||
} |
||||
|
||||
//wpf bug?: Value = -1 updates bindings without coercing, workaround
|
||||
//update: not derived from RangeBase - no problem
|
||||
void SetValue(double newValue) |
||||
{ |
||||
newValue = CoerceValue(newValue); |
||||
if (Value != newValue) { |
||||
Value = newValue; |
||||
} |
||||
} |
||||
|
||||
double CoerceValue(double newValue) |
||||
{ |
||||
return Math.Max(Minimum, Math.Min(newValue, Maximum)); |
||||
} |
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e) |
||||
{ |
||||
base.OnPreviewKeyDown(e); |
||||
if (e.Key == Key.Enter) { |
||||
double result; |
||||
if (double.TryParse(textBox.Text, out result)) { |
||||
SetValue(result); |
||||
} |
||||
else { |
||||
Print(); |
||||
} |
||||
textBox.SelectAll(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.Up) { |
||||
SmallUp(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.Down) { |
||||
SmallDown(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.PageUp) { |
||||
LargeUp(); |
||||
e.Handled = true; |
||||
} |
||||
else if (e.Key == Key.PageDown) { |
||||
LargeDown(); |
||||
e.Handled = true; |
||||
} |
||||
//else if (e.Key == Key.Home) {
|
||||
// Maximize();
|
||||
// e.Handled = true;
|
||||
//}
|
||||
//else if (e.Key == Key.End) {
|
||||
// Minimize();
|
||||
// e.Handled = true;
|
||||
//}
|
||||
} |
||||
|
||||
//protected override void OnMouseWheel(MouseWheelEventArgs e)
|
||||
//{
|
||||
// if (e.Delta > 0)
|
||||
// {
|
||||
// if (Keyboard.IsKeyDown(Key.LeftShift))
|
||||
// {
|
||||
// LargeUp();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SmallUp();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (Keyboard.IsKeyDown(Key.LeftShift))
|
||||
// {
|
||||
// LargeDown();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SmallDown();
|
||||
// }
|
||||
// }
|
||||
// e.Handled = true;
|
||||
//}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
base.OnPropertyChanged(e); |
||||
|
||||
if (e.Property == ValueProperty) { |
||||
Value = CoerceValue((double)e.NewValue); |
||||
Print(); |
||||
} |
||||
else if (e.Property == SmallChangeProperty && |
||||
ReadLocalValue(LargeChangeProperty) == DependencyProperty.UnsetValue) { |
||||
LargeChange = SmallChange * 10; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class DragRepeatButton : RepeatButton |
||||
{ |
||||
public static readonly DependencyProperty IsDraggingProperty = |
||||
DependencyProperty.Register("IsDragging", typeof(bool), typeof(DragRepeatButton)); |
||||
|
||||
public bool IsDragging { |
||||
get { return (bool)GetValue(IsDraggingProperty); } |
||||
set { SetValue(IsDraggingProperty, value); } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:Controls="clr-namespace:ICSharpCode.Core.Presentation"> |
||||
|
||||
<Brush x:Key="ButtonNormal">#DADFEA</Brush> |
||||
<Brush x:Key="ButtonHover">#E6EBEF</Brush> |
||||
<Brush x:Key="ButtonPressed">#B6BDD3</Brush> |
||||
<Brush x:Key="BorderBrush">#7F9DB9</Brush> |
||||
<Brush x:Key="ArrowBrush">Black</Brush> |
||||
<Brush x:Key="ArrowsBorderBrush">#B6BDD3</Brush> |
||||
|
||||
<Style x:Key="UpButton" |
||||
TargetType="RepeatButton"> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}"> |
||||
<Border x:Name="bg" |
||||
Background="{StaticResource ButtonNormal}" |
||||
CornerRadius="2 2 0 0"> |
||||
<Path Fill="{StaticResource ArrowBrush}" |
||||
Data="M 0 3 L 3.5 0 L 7 3" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center" /> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonHover}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsMouseCaptured" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsDragging" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style x:Key="DownButton" |
||||
TargetType="RepeatButton"> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}"> |
||||
<Border x:Name="bg" |
||||
Background="{StaticResource ButtonNormal}" |
||||
CornerRadius="0 0 2 2"> |
||||
<Path Fill="{StaticResource ArrowBrush}" |
||||
Data="M 0 0 L 3.5 3 L 7 0" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center" /> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonHover}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsMouseCaptured" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
<Trigger Property="IsDragging" |
||||
Value="True"> |
||||
<Setter TargetName="bg" |
||||
Property="Background" |
||||
Value="{StaticResource ButtonPressed}" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:NumericUpDown}"> |
||||
<Setter Property="Background" |
||||
Value="White" /> |
||||
<Setter Property="BorderThickness" |
||||
Value="1" /> |
||||
<Setter Property="BorderBrush" |
||||
Value="{StaticResource BorderBrush}" /> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:NumericUpDown}"> |
||||
<Border Background="{TemplateBinding Background}" |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
||||
BorderThickness="{TemplateBinding BorderThickness}" |
||||
Padding="1"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition /> |
||||
<RowDefinition /> |
||||
</Grid.RowDefinitions> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition /> |
||||
<ColumnDefinition Width="15" /> |
||||
</Grid.ColumnDefinitions> |
||||
<TextBox x:Name="PART_TextBox" |
||||
BorderThickness="0" |
||||
Background="{x:Null}" |
||||
Foreground="{TemplateBinding Foreground}" |
||||
Grid.RowSpan="2" /> |
||||
<Controls:DragRepeatButton x:Name="PART_UpButton" |
||||
Style="{StaticResource UpButton}" |
||||
Grid.Column="1" /> |
||||
<Controls:DragRepeatButton x:Name="PART_DownButton" |
||||
Style="{StaticResource DownButton}" |
||||
Grid.Column="1" |
||||
Grid.Row="1" /> |
||||
<Border Grid.Column="1" |
||||
Grid.RowSpan="2" |
||||
BorderBrush="{StaticResource ArrowsBorderBrush}" |
||||
BorderThickness="1" |
||||
CornerRadius="2" /> |
||||
</Grid> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
||||
Loading…
Reference in new issue