Skip to content
Browse files

Fixes #116 (watermark for editable comboboxes).

  • Loading branch information...
1 parent c16e256 commit 35b2dbe6622429355575ef0f40441c32a41f2b1f @vikingcode vikingcode committed Jun 12, 2012
View
10 MahApps.Metro/Controls/TextboxHelper.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -30,7 +31,6 @@ public static void SetWatermark(DependencyObject obj, string value)
{
obj.SetValue(WatermarkProperty, value);
}
-
private static void SetTextLength(DependencyObject obj, int value)
{
@@ -68,14 +68,16 @@ static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedE
static void TextChanged(object sender, TextChangedEventArgs e)
{
var txtBox = sender as TextBox;
- if (txtBox == null) return;
+ if (txtBox == null)
+ return;
SetTextLength(txtBox, txtBox.Text.Length);
}
static void PasswordChanged(object sender, RoutedEventArgs e)
{
var passBox = sender as PasswordBox;
- if (passBox == null) return;
+ if (passBox == null)
+ return;
SetTextLength(passBox, passBox.Password.Length);
}
View
21 MahApps.Metro/Converters/ThicknessToDoubleConverter.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace MahApps.Metro.Converters
+{
+ public class ThicknessToDoubleConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ var thickness = (Thickness) value;
+ return thickness.Left;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
View
1 MahApps.Metro/MahApps.Metro.csproj
@@ -73,6 +73,7 @@
<Compile Include="Controls\WindowCommands.cs" />
<Compile Include="Converters\PanoramaGroupWidthConverter.cs" />
<Compile Include="Converters\PanoramaGroupHeightConverter.cs" />
+ <Compile Include="Converters\ThicknessToDoubleConverter.cs" />
<Compile Include="Native\WINDOWPLACEMENT.cs" />
<Compile Include="Controls\WindowSettings.cs" />
<Compile Include="Native\Constants.cs" />
View
4 MahApps.Metro/Properties/AssemblyInfo.cs
@@ -13,8 +13,8 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
-[assembly: AssemblyVersion("0.7.1.0")]
-[assembly: AssemblyFileVersion("0.7.1.0")]
+[assembly: AssemblyVersion("0.8.0.0")]
+[assembly: AssemblyFileVersion("0.8.0.0")]
[assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/shared", "MahApps.Metro.Behaviours")]
[assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/shared", "MahApps.Metro.Converters")]
[assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/controls", "MahApps.Metro.Controls")]
View
11 MahApps.Metro/Styles/Controls.ComboBox.xaml
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:System="clr-namespace:System;assembly=mscorlib">
-
+ xmlns:System="clr-namespace:System;assembly=mscorlib"
+ xmlns:Controls="clr-namespace:MahApps.Metro.Controls">
+
<Style TargetType="{x:Type ComboBox}">
<Setter Property="MinHeight" Value="26" />
<Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
@@ -10,6 +11,7 @@
<SolidColorBrush Color="{DynamicResource Gray7}" />
</Setter.Value>
</Setter>
+
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="1" />
@@ -190,13 +192,14 @@
HorizontalAlignment="Stretch"
Margin="0,0,23,0"
VerticalAlignment="Stretch">
- <TextBox x:Name="PART_EditableTextBox"
+ <TextBox x:Name="PART_EditableTextBox"
HorizontalAlignment="Stretch"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
- Style="{x:Null}"
BorderThickness="0"
+ Background="{x:Null}"
+ Controls:TextboxHelper.Watermark="{TemplateBinding Controls:TextboxHelper.Watermark}"
Foreground="{TemplateBinding Foreground}"
Focusable="True"
IsReadOnly="{TemplateBinding IsReadOnly}" />
View
10 MahApps.Metro/Styles/Controls.TextBox.xaml
@@ -1,9 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
- xmlns:System="clr-namespace:System;assembly=mscorlib">
+ xmlns:System="clr-namespace:System;assembly=mscorlib"
+ xmlns:Converters="clr-namespace:MahApps.Metro.Converters">
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
+ <Converters:ThicknessToDoubleConverter x:Key="ThicknessToDoubleConverter"/>
<!--TextBox Style-->
<Style TargetType="{x:Type TextBox}">
@@ -70,8 +72,8 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
- <Rectangle x:Name="Base" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" Opacity="1" Fill="{TemplateBinding Background}" />
- <Rectangle x:Name="FocusRectangle" StrokeThickness="{TemplateBinding BorderThickness}" Opacity="0" Stroke="{DynamicResource BlackBrush}" />
+ <Rectangle x:Name="Base" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}}" Opacity="1" Fill="{TemplateBinding Background}" />
+ <Rectangle x:Name="FocusRectangle" StrokeThickness="{TemplateBinding BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}}" Opacity="0" Stroke="{DynamicResource BlackBrush}" />
<Grid Margin="2">
<Border x:Name="ReadOnlyVisualElement" Background="{x:Null}" Opacity="0" />
<ScrollViewer x:Name="PART_ContentHost" BorderThickness="0" IsTabStop="False" Margin="2" VerticalAlignment="Stretch" Background="{x:Null}" />
@@ -83,7 +85,7 @@
</Grid>
<Rectangle x:Name="DisabledVisualElement"
Stroke="{DynamicResource ControlsDisabledBrush}"
- StrokeThickness="{TemplateBinding BorderThickness}"
+ StrokeThickness="{TemplateBinding BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}}"
Fill="{DynamicResource ControlsDisabledBrush}"
IsHitTestVisible="False"
Opacity="0" />
View
2 MetroDemo/MainWindow.xaml
@@ -233,11 +233,13 @@
<!--<Slider Height="23" HorizontalAlignment="Left" Margin="273,119,0,0" Name="slider1" VerticalAlignment="Top" Width="218" Maximum="100" Value="50" />-->
<TextBlock Text="ComboBox Binding scenario" />
<ComboBox ItemsSource="{Binding Tracks}"
+
MaxDropDownHeight="100"
DisplayMemberPath="name" />
<TextBlock Text="Editable ComboBox Binding scenario" />
<ComboBox ItemsSource="{Binding Tracks}"
+ Controls:TextboxHelper.Watermark="watermark"
MaxDropDownHeight="50"
DisplayMemberPath="name" IsEditable="True" Text="{Binding Path=ArtistName, Mode=TwoWay}" IsReadOnly="False" />

0 comments on commit 35b2dbe

Please sign in to comment.
Something went wrong with that request. Please try again.