Window Sizing Questions

Page 1 of 1

7 Replies - 3143 Views - Last Post: 04 October 2013 - 11:38 AM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 84
  • View blog
  • Posts: 557
  • Joined: 14-September 11

Window Sizing Questions

Posted 03 October 2013 - 06:50 AM

I have a window that contains a WebBroswer control, and a few buttons. When the window is rendered, it is huge.. the title bar goes off screen. This is a desktop application, so I guess I could manually set the size I want, but that is bad form, from what I understand. I want the browser control to take up most of the visual space, but I don't want the window to be clipped. Here is the code for the window attributes:

<Window x:Class="CervellaAM.Browser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="winBrowser"
        Title="View Device"
        Background="#FF080808"
        FontFamily="Tahoma"
        FontSize="16"
        Foreground="#FFFDF9F9"
        Icon="Images/icon.ico"
        SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterScreen" HorizontalAlignment="Center" VerticalAlignment="Center">



And for the Browser Control, if that is helpful:

  <WebBrowser x:Name="wb"
        Margin="50"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Navigating="wb_Navigating" />




Am I missing something here? I didn't set the window to maximize or anything like that.

Is This A Good Question/Topic? 1
  • +

Replies To: Window Sizing Questions

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 486
  • Joined: 13-June 12

Re: Window Sizing Questions

Posted 04 October 2013 - 01:53 AM

Yeah, I've tried that, and it is massively annoying. I suspect the problem here is that you have a Window that wants to resize itself according to all its content, and a WebBrowser that wants to fill available window space. It might be one of those occasions where you have to set a MaxHeight and MaxWidth to that control. You could set the MaxHieight and MaxWidth properties of the layout control the WebBrowser is a child of; that seems to work.

What's strange is how little I can find about it using The Developer's Handbook (Google).

EDIT: I thought you might like to read this snippet from Pro WPF 4.5 in C#:

Quote

In WPF, layout is determined by the container that you use. Although there are several containers to
choose from, the “ideal” WPF window follows a few key principles:
• Elements (such as controls) should not be explicitly sized. Instead, they grow to fit
their content. For example, a button expands as you add more text. You can limit
controls to acceptable sizes by setting a maximum and minimum size.
• Elements do not indicate their position with screen coordinates. Instead, they are
arranged by their container based on their size, order, and (optionally) other
information that’s specific to the layout container. If you need to add whitespace
between elements, you use the Margin property.
■ Tip Hard-coded sizes and positions are evil because they limit your ability to localize your interface, and they
make it much more difficult to deal with dynamic content.
• Layout containers “share” the available space among their children. They attempt to
give each element its preferred size (based on its content) if the space is available.
They can also distribute extra space to one or more children.
• Layout containers can be nested. A typical user interface begins with the Grid, WPF’s
most capable container, and contains other layout containers that arrange smaller
groups of elements, such as captioned text boxes, items in a list, icons on a toolbar, a
column of buttons, and so on.

This post has been edited by MrShoes: 04 October 2013 - 06:35 AM

Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 84
  • View blog
  • Posts: 557
  • Joined: 14-September 11

Re: Window Sizing Questions

Posted 04 October 2013 - 06:19 AM

Thanks MrShoes!!! It's working much better now. I didn't even think about setting MaxSize.
Was This Post Helpful? 0
  • +
  • -

#4 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 84
  • View blog
  • Posts: 557
  • Joined: 14-September 11

Re: Window Sizing Questions

Posted 04 October 2013 - 06:42 AM

Oh that's really helpful. I'm flying by the seat of my pants with WPF, learning as I go. I've read a lot of tutorials, but maybe I just break down and pick up a good book.
Was This Post Helpful? 0
  • +
  • -

#5 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 486
  • Joined: 13-June 12

Re: Window Sizing Questions

Posted 04 October 2013 - 07:04 AM

I've found there aren't too many really good tutorials on WPF, that really deal with how things work. They often show you how to do something, but if you don't know how it works, what's the point? You end up making a UI cobbling together the things you do know. I'm reading that book now, and it seems to be very good.
Was This Post Helpful? 1
  • +
  • -

#6 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 84
  • View blog
  • Posts: 557
  • Joined: 14-September 11

Re: Window Sizing Questions

Posted 04 October 2013 - 07:07 AM

I'm thinking because WPF is just not that widely used yet, that a lot of people don't bother to really get under the hood. But, even in just the 4 weeks I've been working with it, I've learned a LOT and it beats the crap out of WinForms.

I just ordered this book, I used an Unleashed book when I was in school, and it was great.
Was This Post Helpful? 1
  • +
  • -

#7 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 486
  • Joined: 13-June 12

Re: Window Sizing Questions

Posted 04 October 2013 - 07:11 AM

What's kind of annoying is that the people who do use WPF use it the same as a WinForms app, because they know how to do that. I've just inherited a project with someone elses' code, where I was told, "It's an MVVM WPF app, just up your alley." Sadly, the person who wrote it (who has conveniently left the company) had only a bare understanding on MVVM, and so there's at least 3 times as much code in each View's code-behind as there is in the View Model. I hate that; for me, there should be little to no code-behind in a WPF app.

Seems like a good book choice, the Unleashed series are pretty good.

This post has been edited by MrShoes: 04 October 2013 - 07:12 AM

Was This Post Helpful? 1
  • +
  • -

#8 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 84
  • View blog
  • Posts: 557
  • Joined: 14-September 11

Re: Window Sizing Questions

Posted 04 October 2013 - 11:38 AM

*snort*

Are you sure I didn't write the program you inherited?

I'm getting there through. Right now I'm trying to correct all the crap I did when I wrote this software, placing controls directly where in the window I wanted them to be, rather than using alignment and margins, etc. And I'm trying to figure out things like, when you have 8 labels and 8 correlated text fields, the best way to line those up and such.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1