Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ButtonsPlacement property to have possibility to set NUD on the left side #2024

Merged
merged 7 commits into from
Jul 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MahApps.Metro/Controls/ButtonsPlacementVariant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MahApps.Metro.Controls
{
public enum ButtonsPlacementVariant
{
Left,
Right
}
}
19 changes: 19 additions & 0 deletions MahApps.Metro/Controls/Helper/TextBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TextBoxHelper
public static readonly DependencyProperty UseFloatingWatermarkProperty = DependencyProperty.RegisterAttached("UseFloatingWatermark", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty TextLengthProperty = DependencyProperty.RegisterAttached("TextLength", typeof(int), typeof(TextBoxHelper), new UIPropertyMetadata(0));
public static readonly DependencyProperty ClearTextButtonProperty = DependencyProperty.RegisterAttached("ClearTextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty ButtonsPlacementProperty = DependencyProperty.RegisterAttached("ButtonsPlacement", typeof(ButtonsPlacementVariant), typeof(TextBoxHelper), new FrameworkPropertyMetadata(ButtonsPlacementVariant.Right, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The clear text button behavior property. It sets a click event to the button if the value is true.
/// </summary>
Expand Down Expand Up @@ -300,6 +301,22 @@ public static void SetClearTextButton(DependencyObject obj, bool value)
obj.SetValue(ClearTextButtonProperty, value);
}

/// <summary>
/// Gets the buttons placement variant.
/// </summary>
public static ButtonsPlacementVariant GetButtonsPlacement(DependencyObject d)
{
return (ButtonsPlacementVariant)d.GetValue(ButtonsPlacementProperty);
}

/// <summary>
/// Sets the buttons placement variant.
/// </summary>
public static void SetButtonsPlacement(DependencyObject obj, ButtonsPlacementVariant value)
{
obj.SetValue(ButtonsPlacementProperty, value);
}

/// <summary>
/// Gets the clear text button behavior.
/// </summary>
Expand All @@ -318,6 +335,8 @@ public static void SetIsClearTextButtonBehaviorEnabled(Button obj, bool value)
obj.SetValue(IsClearTextButtonBehaviorEnabledProperty, value);
}



public static ICommand GetButtonCommand(DependencyObject d)
{
return (ICommand)d.GetValue(ButtonCommandProperty);
Expand Down
17 changes: 16 additions & 1 deletion MahApps.Metro/Controls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ private static void IsReadOnlyPropertyChangedCallback(DependencyObject dependenc
typeof(NumericUpDown),
new FrameworkPropertyMetadata(default(double?), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, CoerceValue));

public static readonly DependencyProperty ButtonsPlacementProperty = DependencyProperty.Register(
"ButtonsPlacement",
typeof(ButtonsPlacementVariant),
typeof(NumericUpDown),
new FrameworkPropertyMetadata(ButtonsPlacementVariant.Right, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));

public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register(
"Minimum",
typeof(double),
Expand Down Expand Up @@ -317,6 +323,15 @@ public double UpDownButtonsWidth
set { SetValue(UpDownButtonsWidthProperty, value); }
}

[Bindable(true)]
[Category("Appearance")]
[DefaultValue(ButtonsPlacementVariant.Right)]
public Controls.ButtonsPlacementVariant ButtonsPlacement
{
get { return (ButtonsPlacementVariant)GetValue(ButtonsPlacementProperty); }
set { SetValue(ButtonsPlacementProperty, value); }
}

[Bindable(true)]
[Category("Behavior")]
[DefaultValue(DefaultInterval)]
Expand Down Expand Up @@ -855,7 +870,7 @@ private static void OnValueChanged(DependencyObject d, DependencyPropertyChanged
numericUpDown.OnValueChanged((double?)e.OldValue, (double?)e.NewValue);
}

private static bool ValidateDelay(object value)
private static bool ValidateDelay(object value)
{
return Convert.ToInt32(value) >= 0;
}
Expand Down
1 change: 1 addition & 0 deletions MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="Behaviours\StylizedBehaviorCollection.cs" />
<Compile Include="Behaviours\TabControlSelectFirstVisibleTabBehavior.cs" />
<Compile Include="Behaviours\WindowsSettingBehaviour.cs" />
<Compile Include="Controls\ButtonsPlacementVariant.cs" />
<Compile Include="Controls\Dialogs\DialogCoordinator.cs" />
<Compile Include="Controls\Dialogs\DialogParticipation.cs" />
<Compile Include="Controls\Dialogs\IDialogCoordinator.cs" />
Expand Down
1 change: 1 addition & 0 deletions MahApps.Metro/MahApps.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="Actions\SetFlyoutOpenAction.cs" />
<Compile Include="Behaviours\BindableResourceBehavior.cs" />
<Compile Include="Behaviours\BorderlessWindowBehavior.cs" />
<Compile Include="Controls\ButtonsPlacementVariant.cs" />
<Compile Include="Controls\Dialogs\DialogCoordinator.cs" />
<Compile Include="Controls\Dialogs\DialogParticipation.cs" />
<Compile Include="Behaviours\GlowWindowBehavior.cs" />
Expand Down
2 changes: 0 additions & 2 deletions MahApps.Metro/Styles/Controls.Expander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@

<Style x:Key="MetroExpander"
TargetType="{x:Type Expander}">
<Setter Property="Margin"
Value="5" />
<Setter Property="Padding"
Value="5" />
<Setter Property="SnapsToDevicePixels"
Expand Down
2 changes: 0 additions & 2 deletions MahApps.Metro/Styles/Controls.StatusBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
Value="1" />
<Setter Property="MinHeight"
Value="1" />
<Setter Property="Margin"
Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
Expand Down
86 changes: 54 additions & 32 deletions MahApps.Metro/Styles/Controls.TextBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
<Grid x:Name="PART_InnerGrid"
Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"
x:Name="TextColumn" />
<ColumnDefinition x:Name="ButtonColumn"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}" />
Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -149,6 +150,7 @@
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
Controls:TextBoxHelper.IsClearTextButtonBehaviorEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay}"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}"
IsTabStop="False" />
</Grid>
<Border x:Name="DisabledVisualElement"
Expand All @@ -161,6 +163,25 @@
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ButtonsPlacement)}"
Value="Left">
<Setter TargetName="PART_ClearText"
Property="Grid.Column"
Value="0" />
<Setter TargetName="Message"
Property="Grid.Column"
Value="1" />
<Setter TargetName="TextColumn"
Property="Width"
Value="Auto" />
<Setter TargetName="ButtonColumn"
Property="Width"
Value="*" />
<Setter TargetName="PART_ContentHost"
Property="Grid.Column"
Value="1" />
</DataTrigger>

<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
Value="">
<Setter TargetName="Message"
Expand Down Expand Up @@ -199,28 +220,21 @@
</DataTrigger.ExitActions>
</DataTrigger>

<!-- multiline textbox cannot bind to actual height so take the fallbach button width -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="TextWrapping"
Value="NoWrap" />
<Condition Property="AcceptsReturn"
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ButtonsPlacement)}"
Value="Right" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ButtonColumn"
Property="Width"
Value="{Binding ElementName=ButtonRow, Path=ActualHeight, Mode=OneWay}" />
</MultiTrigger>

<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
Value="False">
</MultiDataTrigger.Conditions>
<Setter TargetName="PART_ContentHost"
Property="Grid.ColumnSpan"
Value="2" />
<Setter TargetName="Message"
Property="Grid.ColumnSpan"
Value="2" />
</DataTrigger>
</MultiDataTrigger>

<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="Base"
Expand Down Expand Up @@ -381,9 +395,10 @@
<Grid x:Name="PART_InnerGrid"
Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"
x:Name="TextColumn" />
<ColumnDefinition x:Name="ButtonColumn"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}" />
Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -445,6 +460,7 @@
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}"
Controls:TextBoxHelper.IsClearTextButtonBehaviorEnabled="True"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}"
IsTabStop="False" />
</Grid>
<Border x:Name="DisabledVisualElement"
Expand All @@ -457,6 +473,25 @@
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ButtonsPlacement)}"
Value="Left">
<Setter TargetName="PART_ClearText"
Property="Grid.Column"
Value="0" />
<Setter TargetName="Message"
Property="Grid.Column"
Value="1" />
<Setter TargetName="TextColumn"
Property="Width"
Value="Auto" />
<Setter TargetName="ButtonColumn"
Property="Width"
Value="*" />
<Setter TargetName="PART_ContentHost"
Property="Grid.Column"
Value="1" />
</DataTrigger>

<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
Value="">
<Setter TargetName="Message"
Expand Down Expand Up @@ -495,19 +530,6 @@
</DataTrigger.ExitActions>
</DataTrigger>

<!-- multiline textbox cannot bind to actual height so take the fallbach button width -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="TextWrapping"
Value="NoWrap" />
<Condition Property="AcceptsReturn"
Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ButtonColumn"
Property="Width"
Value="{Binding ElementName=ButtonRow, Path=ActualHeight, Mode=OneWay}" />
</MultiTrigger>

<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="Base"
Expand Down
33 changes: 31 additions & 2 deletions MahApps.Metro/Themes/NumericUpDown.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
Background="{TemplateBinding Background}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition x:Name="PART_TextBoxColumn"
Width="*" />
<ColumnDefinition x:Name="PART_NumericUpColumn"
Width="Auto" />
<ColumnDefinition x:Name="PART_NumericDownColumn"
Expand All @@ -85,7 +86,8 @@
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
Controls:TextBoxHelper.ClearTextButton="{TemplateBinding Controls:TextBoxHelper.ClearTextButton}"
Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}" />
Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}"
Controls:TextBoxHelper.ButtonsPlacement="{TemplateBinding ButtonsPlacement}" />
<RepeatButton x:Name="PART_NumericUp"
Grid.Column="1"
Margin="2,2,0,2"
Expand Down Expand Up @@ -128,6 +130,33 @@
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ButtonsPlacement"
Value="Left">
<Setter TargetName="PART_TextBox"
Property="Grid.Column"
Value="2" />
<Setter TargetName="PART_NumericDown"
Property="Grid.Column"
Value="1" />
<Setter TargetName="PART_NumericDown"
Property="Margin"
Value="0,2,2,2" />
<Setter TargetName="PART_NumericUp"
Property="Margin"
Value="2,2,0,2" />
<Setter TargetName="PART_NumericUp"
Property="Grid.Column"
Value="0" />
<Setter TargetName="PART_NumericDownColumn"
Property="Width"
Value="*" />
<Setter TargetName="PART_NumericUpColumn"
Property="Width"
Value="Auto" />
<Setter TargetName="PART_TextBoxColumn"
Property="Width"
Value="Auto" />
</Trigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter TargetName="DisabledVisualElement"
Expand Down
4 changes: 2 additions & 2 deletions samples/MetroDemo/ExampleViews/TextExamples.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@
Maximum="10" />

<Label Content='Interval="2"' />
<Controls:NumericUpDown Value="5"
<Controls:NumericUpDown Value="5" ButtonsPlacement="Left"
IsReadOnly="{Binding ElementName=ReadOnlyCheck, Path=IsChecked, Mode=TwoWay}"
Interval="2" />

<Label Content='Interval="5"' />
<Controls:NumericUpDown Value="5"
IsReadOnly="{Binding ElementName=ReadOnlyCheck, Path=IsChecked, Mode=TwoWay}"
Controls:TextBoxHelper.ClearTextButton="True"
Controls:TextBoxHelper.ClearTextButton="True" ButtonsPlacement="Left"
Interval="5" />

<Controls:NumericUpDown Margin="{StaticResource ControlMargin}"
Expand Down