2

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);
     }
 }
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Tariq
  • 31
  • 5
  • 1
    Don't `answer` yourself unless it is the **actual** answer. Simply update the post to include the *new* text. – ΩmegaMan Jun 29 '15 at 16:51
  • Where are you trying to modify `Top`? Code-behind? Mind to show it? – almulo Jun 29 '15 at 17:01
  • code behind:private void Window_LocationChanged(object sender, EventArgs e) { try { if (this.Top < 55D) this.Top = 55D; Thread.Sleep(25); //Allow window to refresh. } catch { } } – Tariq Jun 29 '15 at 17:10

1 Answers1

0

Are you sure WindowStartupLocation set to Manual? That's the only reason why it shouldn't respect your code.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
norekhov
  • 3,915
  • 25
  • 45