Skip to content

Commit

Permalink
stop large popups, i.e date and time pickers getting truncated on low…
Browse files Browse the repository at this point in the history
… res screens if the control is in the middle of the screen and not enough space above or below
  • Loading branch information
ButchersBoy committed Jun 30, 2015
1 parent 645ca28 commit 99875b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
21 changes: 21 additions & 0 deletions MaterialDesignThemes.Wpf/CustomPopupPlacementCallbackHelper.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace MaterialDesignThemes.Wpf
{
public static class CustomPopupPlacementCallbackHelper
{
public static readonly CustomPopupPlacementCallback LargePopupCallback;

static CustomPopupPlacementCallbackHelper()
{
LargePopupCallback =
(size, targetSize, offset) => new[] {new CustomPopupPlacement(new Point(), PopupPrimaryAxis.Horizontal)};
}
}
}
1 change: 1 addition & 0 deletions MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj
Expand Up @@ -148,6 +148,7 @@
<Compile Include="Converters\ClockLineConverter.cs" />
<Compile Include="Converters\NotConverter.cs" />
<Compile Include="Converters\SizeToRectConverter.cs" />
<Compile Include="CustomPopupPlacementCallbackHelper.cs" />
<Compile Include="DateTimeEx.cs" />
<Compile Include="MaterialDateDisplay.cs" />
<Compile Include="PasswordField.cs" />
Expand Down
Expand Up @@ -134,7 +134,10 @@
Height="17" />
<DatePickerTextBox x:Name="PART_TextBox" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Center" Style="{DynamicResource MaterialDesignDatePickerTextBox}"
HorizontalAlignment="Stretch" />
<Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
<Popup x:Name="PART_Popup" AllowsTransparency="True"
Placement="Custom"
CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
PopupAnimation="Fade" />
</Grid>
</Border>
Expand Down
Expand Up @@ -88,7 +88,10 @@
x:Name="PART_Button"
Height="17"
Template="{StaticResource DropDownButtonTemplate}" />
<Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
<Popup x:Name="PART_Popup" AllowsTransparency="True"
Placement="Custom"
CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
PopupAnimation="Fade"/>
</Grid>
</Border>
Expand Down
15 changes: 7 additions & 8 deletions MaterialDesignThemes.Wpf/TimePicker.cs
Expand Up @@ -19,8 +19,9 @@ public class TimePicker : Control
private const string ElementTextBox = "PART_TextBox";

private readonly ContentControl _clockHostContentControl;
private readonly Clock _clock;
private Popup _popup;
private readonly Clock _clock;
private TextBox _textBox;
private Popup _popup;
private Button _dropDownButton;
private bool _disablePopupReopen;

Expand All @@ -30,8 +31,8 @@ static TimePicker()
}

public TimePicker()
{
_clock = new Clock
{
_clock = new Clock
{
DisplayAutomation = ClockDisplayAutomation.ToMinutesOnly
};
Expand Down Expand Up @@ -142,15 +143,13 @@ public Style ClockStyle
public static readonly DependencyProperty ClockHostContentControlStyleProperty = DependencyProperty.Register(
"ClockHostContentControlStyle", typeof (Style), typeof (TimePicker), new PropertyMetadata(default(Style)));

private TextBox _textBox;

public Style ClockHostContentControlStyle
public Style ClockHostContentControlStyle
{
get { return (Style) GetValue(ClockHostContentControlStyleProperty); }
set { SetValue(ClockHostContentControlStyleProperty, value); }
}

public override void OnApplyTemplate()
public override void OnApplyTemplate()
{
if (_popup != null)
{
Expand Down

0 comments on commit 99875b9

Please sign in to comment.