Skip to content

Commit

Permalink
Merge pull request #1925 from MahApps/1922-IDataErrorInfo-Popup-fix
Browse files Browse the repository at this point in the history
fix validation popup location flicker
  • Loading branch information
punker76 committed May 20, 2015
2 parents 706a27d + 4ca6e2b commit 891942e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
14 changes: 10 additions & 4 deletions MahApps.Metro/Controls/CustomValidationPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private void hostWindow_StateChanged(object sender, EventArgs e)
var holder = target != null ? target.DataContext as AdornedElementPlaceholder : null;
if (holder != null && holder.AdornedElement != null)
{
this.PopupAnimation = PopupAnimation.None;
this.IsOpen = false;
var errorTemplate = holder.AdornedElement.GetValue(Validation.ErrorTemplateProperty);
holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, null);
holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, errorTemplate);
Expand Down Expand Up @@ -153,19 +155,23 @@ private void SetTopmostState(bool isTop)
}
//Debug.WriteLine("setting z-order " + isTop);

var left = rect.left;
var top = rect.top;
var width = rect.Width;
var height = rect.Height;
if (isTop)
{
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOPMOST, left, top, width, height, Constants.TOPMOST_FLAGS);
}
else
{
// Z-Order would only get refreshed/reflected if clicking the
// the titlebar (as opposed to other parts of the external
// window) unless I first set the popup to HWND_BOTTOM
// then HWND_TOP before HWND_NOTOPMOST
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_BOTTOM, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOP, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_NOTOPMOST, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_BOTTOM, left, top, width, height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOP, left, top, width, height, Constants.TOPMOST_FLAGS);
UnsafeNativeMethods.SetWindowPos(hwnd, HWND_NOTOPMOST, left, top, width, height, Constants.TOPMOST_FLAGS);
}

this.appliedTopMost = isTop;
Expand Down
38 changes: 30 additions & 8 deletions MahApps.Metro/Styles/ValidationErrorTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,37 @@
</Grid>
</Border>

<controls:CustomValidationPopup AllowsTransparency="True"
<controls:CustomValidationPopup x:Name="ValidationPopup"
AllowsTransparency="True"
HorizontalAlignment="Right"
HorizontalOffset="0"
VerticalOffset="0"
PopupAnimation="Fade"
Placement="Right"
PlacementTarget="{Binding ElementName=PopupTargetElement}"
IsOpen="{Binding ElementName=placeholder, Path=AdornedElement.IsKeyboardFocusWithin, Mode=OneWay}">
<Grid x:Name="Root" Margin="4">
PlacementTarget="{Binding ElementName=PopupTargetElement, Mode=OneWay}"
IsOpen="False">
<Grid x:Name="Root"
Margin="4">
<Grid.Resources>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Root, Path=IsMouseOver, Mode=OneWay}" Value="True">
<DataTrigger Binding="{Binding ElementName=Root, Path=IsMouseOver, Mode=OneWay}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.15" Duration="0:0:0.1" />
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0.15"
Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.1" />
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1"
Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
Expand Down Expand Up @@ -100,7 +107,7 @@
Margin="8,4,8,4"
TextWrapping="Wrap"
Text="{Binding ErrorContent}"
UseLayoutRounding="false" />
UseLayoutRounding="False" />
</DataTemplate>
</Border.Resources>
<ContentPresenter Content="{Binding CurrentItem}" />
Expand All @@ -110,6 +117,21 @@
</Grid>
</AdornedElementPlaceholder>

<ControlTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=placeholder, Path=AdornedElement.IsKeyboardFocusWithin, Mode=OneWay}"
Value="True">
</Condition>
<Condition Binding="{Binding ElementName=placeholder, Path=AdornedElement.(Validation.HasError), Mode=OneWay}"
Value="True">
</Condition>
</MultiDataTrigger.Conditions>
<Setter TargetName="ValidationPopup"
Property="IsOpen"
Value="True" />
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>

</ResourceDictionary>

0 comments on commit 891942e

Please sign in to comment.