I just upgraded my WPF App target framework from 3.5 to 4.5 and my code for setting the Top
property stopped working, it won't change the top value:
this.Top=45;
it will always stay the previous value, never changed to 45.
I don't have any type of Animations.
Why is it behaving like this?
Window XAML
<Window x:Class="SalesOrderLib.SalesOrderInquiry"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Datepicker="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
xmlns:UI="clr-namespace:SalesOrderLib.Resources.UI"
xmlns:local="clr-namespace:SalesOrderLib"
xmlns:global="clr-namespace:SalesOrderLib.Common"
xmlns:validation="clr-namespace:SalesOrderLib.ValidationRules"
Background="{DynamicResource WinBackgroundBrush}"
Icon="Resources/Images/ToolBar/OrderInquiry.png"
Title="Sales Order - Inquiry Mode"
Height="630"
Width="1024"
WindowState="Normal"
ShowInTaskbar="True"
ResizeMode="CanResize"
WindowStyle="SingleBorderWindow"
WindowStartupLocation="Manual"
FocusManager.FocusedElement="{Binding ElementName=txtOrderNo}"
Loaded="Window_Loaded"
ContentRendered="Window_ContentRendered"
GotFocus="Window_GotFocus"
Closing="Window_Closing"
LocationChanged="Window_LocationChanged"
Activated="Window_Activated">
Here is where I try to set the Top property in code behind:
private void Window_LocationChanged(object sender, EventArgs e)
{
try
{
if (this.Top < 55D)
this.Top = 55D;
if (this.Height > 120D)
this.lstBoxMediaNo.Height = (this.Height - 120D); //Set mediaNo PopUp height.
Thread.Sleep(25); //Allow window to refresh.
}
catch (Exception ex)
{
log.Error(String.Format(GlobalResources.MsgException, ex.ToString(), GetType().Name, MethodBase.GetCurrentMethod().Name));
MessageBox.Show(ex.Message, GlobalResources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
}