Merge branch 'master' into pr/84
This commit is contained in:
commit
e0d3265883
178 files changed
+3147
-1222
No files matched your search
@@ -34,8 +34,8 @@ namespace HandyControl.Controls
|
||||
}
|
||||
else
|
||||
{
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.MinWidthProperty);
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.MinHeightProperty);
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.ActualWidthProperty);
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.ActualHeightProperty);
|
||||
BindingOperations.ClearBinding(border, Border.CornerRadiusProperty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Shapes;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Converter;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class RectangleAttach
|
||||
{
|
||||
public static readonly DependencyProperty CircularProperty = DependencyProperty.RegisterAttached(
|
||||
"Circular", typeof(bool), typeof(RectangleAttach), new PropertyMetadata(ValueBoxes.FalseBox, OnCircularChanged));
|
||||
|
||||
private static void OnCircularChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is Rectangle rectangle)
|
||||
{
|
||||
if ((bool)e.NewValue)
|
||||
{
|
||||
var binding = new MultiBinding
|
||||
{
|
||||
Converter = new RectangleCircularConverter()
|
||||
};
|
||||
binding.Bindings.Add(new Binding(FrameworkElement.ActualWidthProperty.Name) { Source = rectangle });
|
||||
binding.Bindings.Add(new Binding(FrameworkElement.ActualHeightProperty.Name) { Source = rectangle });
|
||||
rectangle.SetBinding(Rectangle.RadiusXProperty, binding);
|
||||
rectangle.SetBinding(Rectangle.RadiusYProperty, binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
BindingOperations.ClearBinding(rectangle, FrameworkElement.ActualWidthProperty);
|
||||
BindingOperations.ClearBinding(rectangle, FrameworkElement.ActualHeightProperty);
|
||||
BindingOperations.ClearBinding(rectangle, Rectangle.RadiusXProperty);
|
||||
BindingOperations.ClearBinding(rectangle, Rectangle.RadiusYProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCircular(DependencyObject element, bool value)
|
||||
=> element.SetValue(CircularProperty, value);
|
||||
|
||||
public static bool GetCircular(DependencyObject element)
|
||||
=> (bool) element.GetValue(CircularProperty);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,15 @@ namespace HandyControl.Controls
|
||||
=> element.SetValue(HighlightBrushProperty, value);
|
||||
|
||||
public static Brush GetHighlightBrush(DependencyObject element)
|
||||
=> (Brush) element.GetValue(HighlightBrushProperty);
|
||||
=> (Brush) element.GetValue(HighlightBrushProperty);
|
||||
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached(
|
||||
"Text", typeof(string), typeof(VisualElement), new PropertyMetadata(default(string)));
|
||||
|
||||
public static void SetText(DependencyObject element, string value)
|
||||
=> element.SetValue(TextProperty, value);
|
||||
|
||||
public static string GetText(DependencyObject element)
|
||||
=> (string) element.GetValue(TextProperty);
|
||||
}
|
||||
}
|
||||
@@ -478,7 +478,7 @@ namespace HandyControl.Controls
|
||||
/// </summary>
|
||||
private void UpdateStatus(Color color)
|
||||
{
|
||||
if (_isOnDragging) return;
|
||||
if (_isOnDragging || _sliderColor == null) return;
|
||||
|
||||
var r = color.R;
|
||||
var g = color.G;
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace HandyControl.Controls
|
||||
/// <param name="pos"></param>
|
||||
private void Remove(int pos)
|
||||
{
|
||||
var item = _itemShowList[pos];
|
||||
if (!_itemShowList.TryGetValue(pos, out var item)) return;
|
||||
_visualParent.Children.Remove(item);
|
||||
_itemShowList.Remove(pos);
|
||||
}
|
||||
@@ -308,10 +308,17 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (content is Uri uri)
|
||||
{
|
||||
return new CoverFlowItem(index, PageIndex, new Image
|
||||
try
|
||||
{
|
||||
Source = BitmapFrame.Create(uri)
|
||||
});
|
||||
return new CoverFlowItem(index, PageIndex, new Image
|
||||
{
|
||||
Source = BitmapFrame.Create(uri, BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand)
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new CoverFlowItem(index, PageIndex, new ContentControl());
|
||||
}
|
||||
}
|
||||
|
||||
return new CoverFlowItem(index, PageIndex, new ContentControl
|
||||
|
||||
@@ -33,6 +33,22 @@ namespace HandyControl.Controls
|
||||
VisibilityProperty.OverrideMetadata(typeof(GifImage), new PropertyMetadata(default(Visibility), OnVisibilityChanged));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty UriProperty = DependencyProperty.Register(
|
||||
"Uri", typeof(Uri), typeof(GifImage), new PropertyMetadata(default(Uri), OnUriChanged));
|
||||
|
||||
private static void OnUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (GifImage) d;
|
||||
var v = (Uri)e.NewValue;
|
||||
ctl.Source = new BitmapImage(v);
|
||||
}
|
||||
|
||||
public Uri Uri
|
||||
{
|
||||
get => (Uri) GetValue(UriProperty);
|
||||
set => SetValue(UriProperty, value);
|
||||
}
|
||||
|
||||
private static void OnVisibilityChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (GifImage)s;
|
||||
@@ -56,10 +72,14 @@ namespace HandyControl.Controls
|
||||
if (DesignerProperties.GetIsInDesignMode(this)) return;
|
||||
if (_isLoaded) return;
|
||||
_isLoaded = true;
|
||||
if (Source is BitmapImage image)
|
||||
if (Uri != null)
|
||||
{
|
||||
var uri = image.UriSource;
|
||||
GetGifStreamFromPack(uri);
|
||||
GetGifStreamFromPack(Uri);
|
||||
StartAnimate();
|
||||
}
|
||||
else if (Source is BitmapImage image)
|
||||
{
|
||||
GetGifStreamFromPack(image.UriSource);
|
||||
StartAnimate();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class ImageBlock : FrameworkElement
|
||||
{
|
||||
private readonly DispatcherTimer _dispatcherTimer;
|
||||
|
||||
private BitmapSource _source;
|
||||
|
||||
private int _indexMax;
|
||||
|
||||
private int _indexMin;
|
||||
|
||||
private int _currentIndex;
|
||||
|
||||
private int _blockWidth;
|
||||
|
||||
private int _blockHeight;
|
||||
|
||||
public ImageBlock()
|
||||
{
|
||||
_dispatcherTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = Interval
|
||||
};
|
||||
_dispatcherTimer.Tick += DispatcherTimer_Tick;
|
||||
}
|
||||
|
||||
private void UpdateDatas()
|
||||
{
|
||||
if (_source == null) return;
|
||||
_indexMin = StartRow * Columns + StartColumn;
|
||||
_indexMax = EndRow * Columns + EndColumn;
|
||||
_currentIndex = _indexMin;
|
||||
_blockWidth = _source.PixelWidth / Columns;
|
||||
_blockHeight = _source.PixelHeight / Rows;
|
||||
}
|
||||
|
||||
private static void OnPositionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ImageBlock)d;
|
||||
ctl.UpdateDatas();
|
||||
}
|
||||
|
||||
private void DispatcherTimer_Tick(object sender, EventArgs e) => InvalidateVisual();
|
||||
|
||||
public static readonly DependencyProperty StartColumnProperty = DependencyProperty.Register(
|
||||
"StartColumn", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int0Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged));
|
||||
|
||||
public int StartColumn
|
||||
{
|
||||
get => (int) GetValue(StartColumnProperty);
|
||||
set => SetValue(StartColumnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StartRowProperty = DependencyProperty.Register(
|
||||
"StartRow", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int0Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged));
|
||||
|
||||
public int StartRow
|
||||
{
|
||||
get => (int) GetValue(StartRowProperty);
|
||||
set => SetValue(StartRowProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EndColumnProperty = DependencyProperty.Register(
|
||||
"EndColumn", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int0Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged));
|
||||
|
||||
public int EndColumn
|
||||
{
|
||||
get => (int) GetValue(EndColumnProperty);
|
||||
set => SetValue(EndColumnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EndRowProperty = DependencyProperty.Register(
|
||||
"EndRow", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int0Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged));
|
||||
|
||||
public int EndRow
|
||||
{
|
||||
get => (int) GetValue(EndRowProperty);
|
||||
set => SetValue(EndRowProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsPlayingProperty = DependencyProperty.Register(
|
||||
"IsPlaying", typeof(bool), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.FalseBox,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnIsPlayingChanged));
|
||||
|
||||
private static void OnIsPlayingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ImageBlock)d;
|
||||
if ((bool) e.NewValue)
|
||||
{
|
||||
ctl._dispatcherTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
ctl._dispatcherTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPlaying
|
||||
{
|
||||
get => (bool) GetValue(IsPlayingProperty);
|
||||
set => SetValue(IsPlayingProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register(
|
||||
"Columns", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int1Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged), obj => (int)obj >= 1);
|
||||
|
||||
public int Columns
|
||||
{
|
||||
get => (int) GetValue(ColumnsProperty);
|
||||
set => SetValue(ColumnsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty RowsProperty = DependencyProperty.Register(
|
||||
"Rows", typeof(int), typeof(ImageBlock), new FrameworkPropertyMetadata(ValueBoxes.Int1Box,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnPositionsChanged), obj => (int)obj >= 1);
|
||||
|
||||
public int Rows
|
||||
{
|
||||
get => (int) GetValue(RowsProperty);
|
||||
set => SetValue(RowsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IntervalProperty = DependencyProperty.Register(
|
||||
"Interval", typeof(TimeSpan), typeof(ImageBlock), new PropertyMetadata(TimeSpan.FromSeconds(1), OnIntervalChanged));
|
||||
|
||||
private static void OnIntervalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ImageBlock) d;
|
||||
ctl._dispatcherTimer.Interval = (TimeSpan) e.NewValue;
|
||||
}
|
||||
|
||||
public TimeSpan Interval
|
||||
{
|
||||
get => (TimeSpan) GetValue(IntervalProperty);
|
||||
set => SetValue(IntervalProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
|
||||
"Source", typeof(ImageSource), typeof(ImageBlock), new FrameworkPropertyMetadata(default(ImageSource),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnSourceChanged));
|
||||
|
||||
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ImageBlock)d;
|
||||
ctl._source = e.NewValue as BitmapSource;
|
||||
ctl.UpdateDatas();
|
||||
}
|
||||
|
||||
public ImageSource Source
|
||||
{
|
||||
get => (ImageSource)GetValue(SourceProperty);
|
||||
set => SetValue(SourceProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
if (_source == null) return;
|
||||
var croppedBitmap = new CroppedBitmap(_source, CalDisplayRect());
|
||||
dc.DrawImage(croppedBitmap, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
|
||||
}
|
||||
|
||||
private Int32Rect CalDisplayRect()
|
||||
{
|
||||
if (_currentIndex > _indexMax)
|
||||
{
|
||||
_currentIndex = _indexMin;
|
||||
}
|
||||
|
||||
var x = _currentIndex % Columns * _blockWidth;
|
||||
var y = _currentIndex / Columns * _blockHeight;
|
||||
|
||||
var rect = new Int32Rect(x, y, _blockWidth, _blockHeight);
|
||||
_currentIndex++;
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,17 +1,16 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class RadioGroup : ItemsControl
|
||||
public class ButtonGroup : ItemsControl
|
||||
{
|
||||
protected override DependencyObject GetContainerForItemOverride() => new RadioButton();
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is RadioButton;
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is Button || item is RadioButton || item is ToggleButton;
|
||||
|
||||
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
|
||||
"Orientation", typeof(Orientation), typeof(RadioGroup), new PropertyMetadata(default(Orientation)));
|
||||
"Orientation", typeof(Orientation), typeof(ButtonGroup), new PropertyMetadata(default(Orientation)));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
@@ -20,7 +19,7 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ItemStyleSelectorProperty = DependencyProperty.Register(
|
||||
"ItemStyleSelector", typeof(StyleSelector), typeof(RadioGroup), new PropertyMetadata(new RadioGroupItemStyleSelector()));
|
||||
"ItemStyleSelector", typeof(StyleSelector), typeof(ButtonGroup), new PropertyMetadata(new ButtonGroupItemStyleSelector()));
|
||||
|
||||
public StyleSelector ItemStyleSelector
|
||||
{
|
||||
@@ -35,9 +34,9 @@ namespace HandyControl.Controls
|
||||
var count = Items.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var item = (RadioButton)Items[i];
|
||||
var item = (ButtonBase)Items[i];
|
||||
item.Style = ItemStyleSelector?.SelectStyle(item, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Card : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
|
||||
"Header", typeof(object), typeof(Card), new PropertyMetadata(default(object)));
|
||||
|
||||
public object Header
|
||||
{
|
||||
get => GetValue(HeaderProperty);
|
||||
set => SetValue(HeaderProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register(
|
||||
"HeaderTemplate", typeof(DataTemplate), typeof(Card), new PropertyMetadata(default(DataTemplate)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplate HeaderTemplate
|
||||
{
|
||||
get => (DataTemplate) GetValue(HeaderTemplateProperty);
|
||||
set => SetValue(HeaderTemplateProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HeaderTemplateSelectorProperty = DependencyProperty.Register(
|
||||
"HeaderTemplateSelector", typeof(DataTemplateSelector), typeof(Card), new PropertyMetadata(default(DataTemplateSelector)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplateSelector HeaderTemplateSelector
|
||||
{
|
||||
get => (DataTemplateSelector) GetValue(HeaderTemplateSelectorProperty);
|
||||
set => SetValue(HeaderTemplateSelectorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty HeaderStringFormatProperty = DependencyProperty.Register(
|
||||
"HeaderStringFormat", typeof(string), typeof(Card), new PropertyMetadata(default(string)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public string HeaderStringFormat
|
||||
{
|
||||
get => (string) GetValue(HeaderStringFormatProperty);
|
||||
set => SetValue(HeaderStringFormatProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty FooterProperty = DependencyProperty.Register(
|
||||
"Footer", typeof(object), typeof(Card), new PropertyMetadata(default(object)));
|
||||
|
||||
public object Footer
|
||||
{
|
||||
get => GetValue(FooterProperty);
|
||||
set => SetValue(FooterProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty FooterTemplateProperty = DependencyProperty.Register(
|
||||
"FooterTemplate", typeof(DataTemplate), typeof(Card), new PropertyMetadata(default(DataTemplate)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplate FooterTemplate
|
||||
{
|
||||
get => (DataTemplate) GetValue(FooterTemplateProperty);
|
||||
set => SetValue(FooterTemplateProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty FooterTemplateSelectorProperty = DependencyProperty.Register(
|
||||
"FooterTemplateSelector", typeof(DataTemplateSelector), typeof(Card), new PropertyMetadata(default(DataTemplateSelector)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public DataTemplateSelector FooterTemplateSelector
|
||||
{
|
||||
get => (DataTemplateSelector) GetValue(FooterTemplateSelectorProperty);
|
||||
set => SetValue(FooterTemplateSelectorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty FooterStringFormatProperty = DependencyProperty.Register(
|
||||
"FooterStringFormat", typeof(string), typeof(Card), new PropertyMetadata(default(string)));
|
||||
|
||||
[Bindable(true), Category("Content")]
|
||||
public string FooterStringFormat
|
||||
{
|
||||
get => (string) GetValue(FooterStringFormatProperty);
|
||||
set => SetValue(FooterStringFormatProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace HandyControl.Controls
|
||||
_itemsControl = GetTemplateChild(ElementItemsControl) as ItemsPresenter;
|
||||
_panelPage = GetTemplateChild(ElementPanelPage) as Panel;
|
||||
|
||||
CheckNull();
|
||||
if (!CheckNull()) return;
|
||||
|
||||
_panelPage.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ButtonPages_OnClick));
|
||||
_appliedTemplate = true;
|
||||
@@ -74,10 +74,7 @@ namespace HandyControl.Controls
|
||||
UpdatePageButtons(_pageIndex);
|
||||
}
|
||||
|
||||
private void CheckNull()
|
||||
{
|
||||
if (_itemsControl == null || _panelPage == null) throw new Exception();
|
||||
}
|
||||
private bool CheckNull() => !(_itemsControl == null || _panelPage == null);
|
||||
|
||||
public static readonly DependencyProperty AutoRunProperty = DependencyProperty.Register(
|
||||
"AutoRun", typeof(bool), typeof(Carousel), new PropertyMetadata(ValueBoxes.FalseBox, (o, args) =>
|
||||
@@ -195,6 +192,7 @@ namespace HandyControl.Controls
|
||||
/// </summary>
|
||||
public void UpdatePageButtons(int index = -1)
|
||||
{
|
||||
if (!CheckNull()) return;
|
||||
if (!_appliedTemplate) return;
|
||||
|
||||
var count = Items.Count;
|
||||
@@ -236,6 +234,7 @@ namespace HandyControl.Controls
|
||||
/// </summary>
|
||||
private void UpdateItemsPosition()
|
||||
{
|
||||
if (!CheckNull()) return;
|
||||
if (!_appliedTemplate) return;
|
||||
if (Items.Count == 0) return;
|
||||
if (!IsCenter)
|
||||
@@ -284,6 +283,7 @@ namespace HandyControl.Controls
|
||||
|
||||
private void ButtonPages_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!CheckNull()) return;
|
||||
if (_selectedButton != null && _selectedButton.Content is Border borderOri)
|
||||
borderOri.Background = Brushes.White;
|
||||
_selectedButton = e.OriginalSource as Button;
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class Dialog : ContentControl
|
||||
{
|
||||
private string _token;
|
||||
|
||||
private Adorner _container;
|
||||
|
||||
private static readonly Dictionary<string, System.Windows.Window> WindowDic = new Dictionary<string, System.Windows.Window>();
|
||||
@@ -99,6 +101,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
var dialog = new Dialog
|
||||
{
|
||||
_token = token,
|
||||
Content = content
|
||||
};
|
||||
|
||||
@@ -139,19 +142,16 @@ namespace HandyControl.Controls
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void Close(string token = "")
|
||||
public void Close()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
if (WindowDic.TryGetValue(token, out var window))
|
||||
{
|
||||
Close(window);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (string.IsNullOrEmpty(_token))
|
||||
{
|
||||
Close(VisualHelper.GetActiveWindow());
|
||||
}
|
||||
else if (WindowDic.TryGetValue(_token, out var window))
|
||||
{
|
||||
Close(window);
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(System.Windows.Window window)
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Interactivity;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementVisualBrush, Type = typeof(VisualBrush))]
|
||||
public class Magnifier : Control
|
||||
{
|
||||
private Size _viewboxSize;
|
||||
|
||||
private AdornerContainer _adorner;
|
||||
|
||||
private UIElement _elementTarget;
|
||||
|
||||
private const string ElementVisualBrush = "PART_VisualBrush";
|
||||
|
||||
private VisualBrush _visualBrush = new VisualBrush();
|
||||
|
||||
private readonly TranslateTransform _translateTransform;
|
||||
|
||||
public static readonly DependencyProperty HorizontalOffsetProperty = DependencyProperty.Register(
|
||||
"HorizontalOffset", typeof(double), typeof(Magnifier), new PropertyMetadata(ValueBoxes.Double0Box));
|
||||
|
||||
public double HorizontalOffset
|
||||
{
|
||||
get => (double) GetValue(HorizontalOffsetProperty);
|
||||
set => SetValue(HorizontalOffsetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty VerticalOffsetProperty = DependencyProperty.Register(
|
||||
"VerticalOffset", typeof(double), typeof(Magnifier), new PropertyMetadata(ValueBoxes.Double0Box));
|
||||
|
||||
public double VerticalOffset
|
||||
{
|
||||
get => (double) GetValue(VerticalOffsetProperty);
|
||||
set => SetValue(VerticalOffsetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InstanceProperty = DependencyProperty.RegisterAttached(
|
||||
"Instance", typeof(Magnifier), typeof(Magnifier), new PropertyMetadata(default(Magnifier), OnMagnifierChanged));
|
||||
|
||||
private static void OnMagnifierChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is UIElement target)) return;
|
||||
var magnifier = (Magnifier)e.NewValue;
|
||||
magnifier.Target = target;
|
||||
}
|
||||
|
||||
public static void SetInstance(DependencyObject element, Magnifier value)
|
||||
=> element.SetValue(InstanceProperty, value);
|
||||
|
||||
public static Magnifier GetInstance(DependencyObject element)
|
||||
=> (Magnifier) element.GetValue(InstanceProperty);
|
||||
|
||||
public static Magnifier Default => new Magnifier();
|
||||
|
||||
internal static readonly DependencyProperty TargetProperty = DependencyProperty.Register(
|
||||
"Target", typeof(UIElement), typeof(Magnifier), new PropertyMetadata(default(UIElement), OnTargetChanged));
|
||||
|
||||
private static void OnTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Magnifier) d;
|
||||
ctl.UpdateTarget(ctl._elementTarget, false);
|
||||
ctl.UpdateTarget((UIElement)e.NewValue, true);
|
||||
}
|
||||
|
||||
internal UIElement Target
|
||||
{
|
||||
get => (UIElement)GetValue(TargetProperty);
|
||||
set => SetValue(TargetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
|
||||
"Scale", typeof(double), typeof(Magnifier), new PropertyMetadata(5.0, OnScaleChanged), ValidateHelper.IsInRangeOfPosDouble);
|
||||
|
||||
private static void OnScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((Magnifier)d).UpdateViewboxSize();
|
||||
|
||||
public double Scale
|
||||
{
|
||||
get => (double)GetValue(ScaleProperty);
|
||||
set => SetValue(ScaleProperty, value);
|
||||
}
|
||||
|
||||
public Magnifier()
|
||||
{
|
||||
_translateTransform = new TranslateTransform();
|
||||
RenderTransform = _translateTransform;
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
var visualBrush = GetTemplateChild(ElementVisualBrush) as VisualBrush ?? new VisualBrush();
|
||||
visualBrush.Viewbox = _visualBrush.Viewbox;
|
||||
_visualBrush = visualBrush;
|
||||
}
|
||||
|
||||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
||||
{
|
||||
base.OnRenderSizeChanged(sizeInfo);
|
||||
UpdateViewboxSize();
|
||||
}
|
||||
|
||||
private void UpdateViewboxSize() => _viewboxSize = new Size(ActualWidth / Scale, ActualHeight / Scale);
|
||||
|
||||
private void UpdateTarget(UIElement element , bool isNew)
|
||||
{
|
||||
if (element == null) return;
|
||||
|
||||
if (!isNew)
|
||||
{
|
||||
element.MouseEnter -= Element_MouseEnter;
|
||||
element.MouseLeave -= Element_MouseLeave;
|
||||
element.MouseMove -= Element_MouseMove;
|
||||
_elementTarget = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
element.MouseEnter += Element_MouseEnter;
|
||||
element.MouseLeave += Element_MouseLeave;
|
||||
element.MouseMove += Element_MouseMove;
|
||||
_elementTarget = element;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLocation()
|
||||
{
|
||||
var targetPoint = Mouse.GetPosition(Target);
|
||||
var subX = targetPoint.X - _visualBrush.Viewbox.Width / 2;
|
||||
var subY = targetPoint.Y - _visualBrush.Viewbox.Height / 2;
|
||||
|
||||
var targetVector = VisualTreeHelper.GetOffset(Target);
|
||||
_visualBrush.Viewbox = new Rect(new Point(subX + targetVector.X, subY + targetVector.Y), _viewboxSize);
|
||||
|
||||
var adornerPoint = Mouse.GetPosition(_adorner);
|
||||
_translateTransform.X = adornerPoint.X + HorizontalOffset;
|
||||
_translateTransform.Y = adornerPoint.Y + VerticalOffset;
|
||||
}
|
||||
|
||||
private void Element_MouseMove(object sender, MouseEventArgs e) => UpdateLocation();
|
||||
|
||||
private void Element_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
var layer = AdornerLayer.GetAdornerLayer(Target);
|
||||
if (layer == null) return;
|
||||
layer.Remove(_adorner);
|
||||
_adorner.Child = null;
|
||||
_adorner = null;
|
||||
}
|
||||
|
||||
private void Element_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (_adorner == null)
|
||||
{
|
||||
var layer = AdornerLayer.GetAdornerLayer(Target);
|
||||
if (layer == null) return;
|
||||
_adorner = new AdornerContainer(layer)
|
||||
{
|
||||
Child = this
|
||||
};
|
||||
layer.Add(_adorner);
|
||||
}
|
||||
this.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@ namespace HandyControl.Controls
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Prev, ButtonPrev_OnClick));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Next, ButtonNext_OnClick));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Selected, ToggleButton_OnChecked));
|
||||
this.Show(MaxPageCount > 1);
|
||||
}
|
||||
|
||||
#region Public Properties
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// 切换块
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 在不需要命中测试的情况下可代替ToggleButton或CheckBox,以减少内存用量。
|
||||
/// </remarks>
|
||||
public class ToggleBlock : Control
|
||||
{
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||
"IsChecked", typeof(bool?), typeof(ToggleBlock), new FrameworkPropertyMetadata(ValueBoxes.FalseBox,
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal));
|
||||
|
||||
[Category("Appearance")]
|
||||
[TypeConverter(typeof(NullableBoolConverter))]
|
||||
[Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]
|
||||
public bool? IsChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
// Because Nullable<bool> unboxing is very slow (uses reflection) first we cast to bool
|
||||
var value = GetValue(IsCheckedProperty);
|
||||
// ReSharper disable once RedundantExplicitNullableCreation
|
||||
return value == null ? new bool?() : new bool?((bool)value);
|
||||
}
|
||||
set => SetValue(IsCheckedProperty, value.HasValue ? ValueBoxes.BooleanBox(value.Value) : null);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CheckedContentProperty = DependencyProperty.Register(
|
||||
"CheckedContent", typeof(object), typeof(ToggleBlock), new PropertyMetadata(default(object)));
|
||||
|
||||
public object CheckedContent
|
||||
{
|
||||
get => GetValue(CheckedContentProperty);
|
||||
set => SetValue(CheckedContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty UnCheckedContentProperty = DependencyProperty.Register(
|
||||
"UnCheckedContent", typeof(object), typeof(ToggleBlock), new PropertyMetadata(default(object)));
|
||||
|
||||
public object UnCheckedContent
|
||||
{
|
||||
get => GetValue(UnCheckedContentProperty);
|
||||
set => SetValue(UnCheckedContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IndeterminateContentProperty = DependencyProperty.Register(
|
||||
"IndeterminateContent", typeof(object), typeof(ToggleBlock), new PropertyMetadata(default(object)));
|
||||
|
||||
public object IndeterminateContent
|
||||
{
|
||||
get => GetValue(IndeterminateContentProperty);
|
||||
set => SetValue(IndeterminateContentProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace HandyControl.Controls
|
||||
[TemplatePart(Name = OverflowScrollviewer, Type = typeof(ScrollViewer))]
|
||||
[TemplatePart(Name = ScrollButtonLeft, Type = typeof(Button))]
|
||||
[TemplatePart(Name = ScrollButtonRight, Type = typeof(Button))]
|
||||
[TemplatePart(Name = HeaderBorder, Type = typeof(Border))]
|
||||
public class TabControl : System.Windows.Controls.TabControl
|
||||
{
|
||||
private const string OverflowButtonKey = "PART_OverflowButton";
|
||||
@@ -27,6 +28,8 @@ namespace HandyControl.Controls
|
||||
|
||||
private const string ScrollButtonRight = "PART_ScrollButtonRight";
|
||||
|
||||
private const string HeaderBorder = "PART_HeaderBorder";
|
||||
|
||||
private ContextMenuToggleButton _buttonOverflow;
|
||||
|
||||
private TabPanel _headerPanel;
|
||||
@@ -37,6 +40,8 @@ namespace HandyControl.Controls
|
||||
|
||||
private Button _buttonScrollRight;
|
||||
|
||||
private Border _headerBorder;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为内部操作
|
||||
/// </summary>
|
||||
@@ -220,6 +225,9 @@ namespace HandyControl.Controls
|
||||
item.TabPanel = _headerPanel;
|
||||
}
|
||||
}
|
||||
|
||||
_headerBorder?.InvalidateMeasure();
|
||||
|
||||
IsInternalAction = false;
|
||||
}
|
||||
|
||||
@@ -248,6 +256,7 @@ namespace HandyControl.Controls
|
||||
_scrollViewerOverflow = GetTemplateChild(OverflowScrollviewer) as ScrollViewer;
|
||||
_buttonScrollLeft = GetTemplateChild(ScrollButtonLeft) as Button;
|
||||
_buttonScrollRight = GetTemplateChild(ScrollButtonRight) as Button;
|
||||
_headerBorder = GetTemplateChild(HeaderBorder) as Border;
|
||||
|
||||
if (_buttonScrollLeft != null) _buttonScrollLeft.Click += ButtonScrollLeft_Click;
|
||||
if (_buttonScrollRight != null) _buttonScrollRight.Click += ButtonScrollRight_Click;
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -400,6 +400,7 @@ namespace HandyControl.Controls
|
||||
|
||||
private void TimeBar_OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
if (_canvasSpe == null) return;
|
||||
_speBlockList.Clear();
|
||||
_canvasSpe.Children.Clear();
|
||||
|
||||
@@ -442,7 +443,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
var p = Mouse.GetPosition(this);
|
||||
var mlliseconds = (p.X - ActualWidth / 2) / _itemWidth * _timeSpeList[_speIndex];
|
||||
if (double.IsInfinity(mlliseconds)) return;
|
||||
if (double.IsNaN(mlliseconds) || double.IsInfinity(mlliseconds)) return;
|
||||
_textBlockMove.Text = mlliseconds < 0
|
||||
? (SelectedTime - TimeSpan.FromMilliseconds(-mlliseconds)).ToString(TimeFormat)
|
||||
: (SelectedTime + TimeSpan.FromMilliseconds(mlliseconds)).ToString(TimeFormat);
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace HandyControl.Controls
|
||||
new PropertyMetadata(ValueBoxes.TrueBox, OnShowNonClientAreaChanged));
|
||||
|
||||
public static readonly DependencyProperty ShowTitleProperty = DependencyProperty.Register(
|
||||
"ShowTitle", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
"ShowTitle", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register(
|
||||
"IsFullScreen", typeof(bool), typeof(Window),
|
||||
@@ -94,11 +94,20 @@ namespace HandyControl.Controls
|
||||
|
||||
public Window()
|
||||
{
|
||||
#if netle40
|
||||
var chrome = new WindowChrome
|
||||
{
|
||||
CornerRadius = new CornerRadius(),
|
||||
GlassFrameThickness = new Thickness(0, 0, 0, 1)
|
||||
};
|
||||
#else
|
||||
var chrome = new WindowChrome
|
||||
{
|
||||
CornerRadius = new CornerRadius(),
|
||||
GlassFrameThickness = new Thickness(0, 0, 0, 1),
|
||||
UseAeroCaptionButtons = false
|
||||
};
|
||||
#endif
|
||||
BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty,
|
||||
new Binding(NonClientAreaHeightProperty.Name) {Source = this});
|
||||
WindowChrome.SetWindowChrome(this, chrome);
|
||||
|
||||
Reference in new issue
Block a user