.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Saving and restoring WPF Window size and position

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :WPF
I have a WPF window.  I want to do a very common thing:  Save the window size and position on close and restore them on open. I tried a C# approach and a XAML approach. I prefer the XAML but I'l take advise on either.  Here's the XAML I've tried: Title ="PVIEW" ResizeMode="CanMinimize" BorderThickness="0" WindowStartupLocation="CenterScreen" WindowStyle="SingleBorderWindow" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Loaded="Window_Loaded" Closing="Window_Closing" Closed="Window_Closed" SizeChanged="Window_SizeChanged" Height="{Binding Source={x:Static self:Properties.Settings.Default}, Path=LastWindowHeight, Mode=TwoWay}" Width="{Binding Source={x:Static self:Properties.Settings.Default}, Path=LastWindowWidth, Mode=TwoWay}" Top ="{Binding Source={x:Static self:Properties.Settings.Default}, Path=LastWindowTop, Mode=TwoWay}" Left ="{Binding Source={x:Static self:Properties.Settings.Default}, Path=LastWindowLeft, Mode=TwoWay}"> ... In Settings, I also created four entries, (all doubles) with the same names as the Path names above with all their values set to 0. Then I added this line to Window_Closing:  "Properties . Settings . Default.Save(

View Complete Post

More Related Resource Links

Lock the window size to uniform in wpf

I have a window that contain a ViewBox. The ViewBox's Streach property is set to Uniform. And I want to set the window size to be uniform! that means the Height And Width properties are relative to each other.

size of window on desktop

i have read all the threads related to this but all i am getting is the size of the canvas in the window, i want the size of the window currently showing on desktop please help me out?   thanks

How can I change the WPF window title bar size through Interop services

Hi all,      I want to use my custom title bar in my custom window. In that need a title bar with more height than default widow title bar height. How can I achieve this through window Interop services???? Thanks in Advance.. Suresh.

Get the Window Position from an external Process

Hi all, Well, this time I am pretending to get the size and the position of a windows process. In fact the size is not relevant to me cause it has always the same, but the position not. Showing the code Code Snippetprivate Process FindWindow(){    Process[] procesos = Process.GetProcesses();        for (int i = 0; i < procesos.Length; i++)    {        if (procesos[i].ToString().Contains("WindowTitle"))        {            return procesos[i];        }    }    return null;}I callProcess WindowA = FinWindow ();At this point i need to know how to get the windows position of that processThank,

Restoring a Visual Element to its initial position in WPF application


Hi there, I'm implementing a WPF application where one can drag & drop a element in a designated area where this element is restored to its initial position. The drag & drop is working, and already have the events for the dragging and drop actions; my problem is how to restore the visual element to the correct position, previously stored (of course).

The elements are within a Grid, and it looks like this is preventing me of using the Canvas.GetLeft()and Canvas.SetLeft() methods, and because of that I've saved the initial Margin property as the origin for the object. The problem resides in the fact if I, set the margin to the origin in the drop event, it won't work.

If someone know how to do this please let me know.

Note: the reason for the fact that I'm using the grid is because the application has a fullscreen function and I want the elements to be rearranged in the same position in fullscreen or window modes.

Window size

hi friends,
How can I change the Window size when a window opens
I put a url in Hyperlink and target is Blank now hen the Navigate url opens I want to change the Sixe of the Window , project is as i said and do not want to make popup window !

All the best

Something changes my window's size


Hi there

Im using windows 7 and visual studio 2008 c#

Can someone explain me why the size of my windows form changes by itself? Let me explain a little bit more.

I create a simple windows forms application with form1 and just a label showing me the actual size of the form:

label1.Text = String.Format("Width = {0}, Height = {1}", this.Width, this.Height);

i give it the size of 800, 600 in the form's property SIZE

i run the applicacion

In windows 7 i get 800,600 good, but  i run it on windows server 2008 or in windows xp and i get 594,478 ???

i give it the size of 1024,768

In windows 7 i get 1024,768 ok, but in windows server 2008 or in windows xp and i get 762,614 ???

i give it the size of 1280,800

In windows 7 i get 1280,800 ok, but in windows server 2008 or in windows xp and i get 779.639 ???

Does anybody knows why?

Help most appreciated



Resize image and get new byte size without saving it


Hi Guys,

I'm making an application that needs to be able to take a user specified image file and upload it into a database that only accepts images of 10 KB or less. So I want to let the user select an image and then have the option of resizing it and if possible also decreasing the quality - I'm sure I can figure out how to do both of these things on my own but the thing I'm not sure about is how I can tell what size the resulting image will be without actually writing it to disk. I thought the SourceStream property of the BitmapSource class would be useful but when I try to access it I just get told that the stream has been closed. Any ideas?




My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com

How to take a screenshot of a Full Size window in C#


Hi I am trying to create an application in C#.net that captures the screenshot of the current active including the area that has to be scrolled using scroll bars.I found the following code to take screenshot. TO be very clear I want the code to take screenshot of the active window including the area that is not displayed and is only revealed by using scroll bars. Any help is greatly appreciated.Thank you


public class ScreenShot
    /// <summary>
    /// Captures the screenshot of the entire desktop
    /// </summary>
    /// <returns>Image object containing the screenshot of the desktop</returns>
    private Image CaptureDesktop()
      return CaptureWindow(User32.GetDesktop

Adjust application window size per screen resolution on different computers


I have built an  application which calls two dialog boxes defined in a .rc file.

When this application was run on a computer with a screen resolution of 600 x 800

the dialog boxes were not fully displayed.  How can I automatically adjust for different screen resolutions?

Reduce ASP.NET Page size and complexity using JQuery

This is my first post on asp.net blog. ASP.NET Ajax and JQuery are two different ajax framework. In this post I will show, how we can enhance gridview using ASP.NET Ajax and JQuery. I also compare the implementation of these frameworks. In next posts i will explain more about JQuery and ASP.NET Ajax and also tell you "How to combine the power of both framework". My Future post will related to ASP.NET and related frameworks.

Modal popup window in ASP.Net

A Masked div or modal popup window is a child window created from the parent window which prevents the user from interacting with parent window before he returns to the parent application.

The Free Barcode Creator produces barcode images one at a time, and allows easy saving to a file or

The Free Barcode Creator produces barcode images one at a time, and allows easy saving to a file or pasting into an application. 2D versions are also available:

Set Custom Paper size in C#.net 3.5


Dear All,

I have to set custom paper size 6X8 inches

plz tell sugest me code how to do it.

in C#.net 3.5

i m using Asp.net 3.5 Crystal report

i have to do it programiticlly



Does this look correct for saving a file/ new record to a database


So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)

the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name=

lossing focus from model pop up window controls


hi i using a model pop up window with some textbox but when i click on textbox of model pop up focus move to back to page textbox control plz help me 

How to position one control relative to another one even after resizing windows?


I used following Jquery code trying to make image close to a table. It worked fine after first load, but the position changed after window is resized. Any ideas? thanks

$(document).ready(function() {
            var pos = $("#mytable").offset();
            var width = $("#mytable").width();
            var left = pos.left + width + 20;
            var top = pos.top + 200;
                position: 'absolute',
                zIndex: 5000,
                left: left,
                top: top

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend