forked from MaterialDesignInXAML/MaterialDesignInXamlToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextField.cs
More file actions
66 lines (55 loc) · 2.35 KB
/
Copy pathTextField.cs
File metadata and controls
66 lines (55 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace MaterialDesignThemes.Wpf
{
public static class TextField
{
public static readonly DependencyProperty TextBoxViewMarginProperty = DependencyProperty.RegisterAttached(
"TextBoxViewMargin", typeof (Thickness), typeof (TextField), new PropertyMetadata(new Thickness(double.NegativeInfinity), TextBoxViewMarginPropertyChangedCallback));
private static void TextBoxViewMarginPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var textBoxBase = dependencyObject as TextBoxBase;
if (textBoxBase == null) return;
if (textBoxBase.IsLoaded)
ApplyTextBoxViewMargin(textBoxBase, (Thickness)dependencyPropertyChangedEventArgs.NewValue);
textBoxBase.Loaded += (sender, args) =>
{
var textBox = (TextBoxBase) sender;
ApplyTextBoxViewMargin(textBox, GetTextBoxViewMargin(textBox));
};
}
public static void SetTextBoxViewMargin(DependencyObject element, Thickness value)
{
element.SetValue(TextBoxViewMarginProperty, value);
}
public static Thickness GetTextBoxViewMargin(DependencyObject element)
{
return (Thickness) element.GetValue(TextBoxViewMarginProperty);
}
private static void ApplyTextBoxViewMargin(TextBoxBase textBox, Thickness margin)
{
var scrollViewer = textBox.Template.FindName("PART_ContentHost", textBox) as ScrollViewer;
if (scrollViewer == null) return;
var frameworkElement = scrollViewer.Content as FrameworkElement;
//remove nice new sytax until i get appveyor working
//var frameworkElement = (textBox.Template.FindName("PART_ContentHost", textBox) as ScrollViewer)?.Content as FrameworkElement;
if (frameworkElement != null)
frameworkElement.Margin = margin;
}
public static readonly DependencyProperty HintProperty = DependencyProperty.RegisterAttached(
"Hint", typeof (string), typeof (TextField), new PropertyMetadata(default(string)));
public static void SetHint(DependencyObject element, string value)
{
element.SetValue(HintProperty, value);
}
public static string GetHint(DependencyObject element)
{
return (string) element.GetValue(HintProperty);
}
}
}