Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto Height in combination with MaxHeight
    primarykey
    data
    text
    <p>I am facing a problem with setting the following xaml layout:</p> <p>RowHeightAuto.xaml</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="GridMaxHeight.RowHeightAuto" Title="RowHeightAuto" WindowState="Maximized"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height="Auto" MaxHeight="200" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Background="LightGray" Grid.Row="0"&gt;&lt;/StackPanel&gt; &lt;DataGrid Name="DataGrid1" Grid.Row="1" /&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>The DataGrid1 control isn't showing any scrollbars with a lot of columns and rows defined. Everything works find when I would replace the Height="Auto" with Height="*" than Horizontal and Vertical scrollbars appear like expected.</p> <p>Also it works when I would declare the MaxHeight directly at the DataGrid1, but that's not really want I want.</p> <p>Is this a bug that the childcontrol ignores the maxheight on setting Height="Auto" or am I propably making something wrong? Same behaviour can be reproduced with ListBox/ListView and so on, also with third party controls like ComponentOne, Telerik...</p> <p>If it's a bug - do you know a workaround or have other hints for me?</p> <p>Here is the code how I set the ItemsSource of the DataGrid. RowHeightAuto.xaml.cs</p> <pre><code>public partial class RowHeightAuto : Window { private readonly DateTime _start; public RowHeightAuto() { InitializeComponent(); DataGrid1.ItemsSource = GetTestData(); _start = DateTime.Now; Dispatcher.BeginInvoke(new Action(() =&gt; MessageBox.Show((DateTime.Now - _start).TotalSeconds.ToString(CultureInfo.InvariantCulture))), DispatcherPriority.ContextIdle, null); } public static List&lt;TestData&gt; GetTestData() { const int maxCols = 501; const int maxRows = 300; var testDatas = new List&lt;TestData&gt;(maxRows); for (int i = 0; i &lt; maxRows; i++) testDatas.Add(new TestData()); for (int i = 0; i &lt; maxCols; i++) { string propName = string.Format("Property{0}", AddLeadingZeros(i)); for (int j = 0; j &lt; maxRows; j++) testDatas[j][propName] = propName; } return testDatas; } private static string AddLeadingZeros(int val) { return val.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'); } } public class TestData { public object this[string propertyName] { get { var myType = GetType(); var myPropInfo = myType.GetProperty(propertyName); return myPropInfo.GetValue(this); } set { var myType = GetType(); var myPropInfo = myType.GetProperty(propertyName); myPropInfo.SetValue(this, value, null); } } public string Property000 { get; set; } public string Property001 { get; set; } public string Property002 { get; set; } public string Property003 { get; set; } ... public string Property498 { get; set; } public string Property499 { get; set; } public string Property500 { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload