1

Is there a control in WPF that let's me define 1 or more layout for a user control based on the window's size.

Say with a resolution of 1280 x 800, I would have a Grid control with 4 columns to display my data, but with a resolution of 800 x 600, I would only a Grid control with 2 columns, so that it does look crushed.

For example

<Layouts>
 <Layout x:key="1280x800">
  <Grid/> with 4 columns
 </Layout>
 <Layout x:key="800x600">
  <Grid /> with 2 columns
 </Layout>
</Layouts>
Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
Julien Pierre
  • 467
  • 1
  • 6
  • 29

1 Answers1

7

You can use a ContentControl which has it's Content or ContentTemplate property set via a DataTrigger bound to either the SystemParameters of the window, or the ActualHeight/ActualWidth of the window.

You may also need an IValueConverter, since Triggers only test if a value is equal to something, and you may need to test if the Screen Height/Width is greater than or less than a particular value.

Also, WPF doesn't actually scale based on screen resolution. To quote this SO answer

Keep in mind that all WPF locations and sizes are floating point with a unit of 1/96 inch. Not pixels. This makes your window designs resolution independent. Doing the math: height = 960 / 96 = 10 inches. With your video adapter set to 120 DPI (120/96 = 125%): 10 * 120 = 1200 pixels. Same for width: 1536 / 96 * 120 = 1920 pixels.

Community
  • 1
  • 1
Rachel
  • 130,264
  • 66
  • 304
  • 490