Jestem stoi problem z ustawieniem następujący układ: XAMLAuto Wzrost w połączeniu z maxheight
RowHeightAuto.xaml
<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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" MaxHeight="200" />
</Grid.RowDefinitions>
<StackPanel Background="LightGray" Grid.Row="0"></StackPanel>
<DataGrid Name="DataGrid1" Grid.Row="1" />
</Grid>
Kontrola DataGrid1 nie widać żadnych pasków przewijania z zdefiniowano wiele kolumn i wierszy. Wszystko działa, gdy zastępuję Wysokość = "Auto" z Wysokością = "*" niż paski przewijania w poziomie i pionie są wyświetlane tak, jak oczekiwano.
Działa również wtedy, gdy zadeklaruję MaxHeight bezpośrednio w DataGrid1, ale tak naprawdę nie chcę, chcę.
Czy jest to błąd, w którym sterowanie dziećmi ignoruje maksymalną wysokość ustawienia wysokości "Auto" lub czy proponuję coś nie tak? To samo zachowanie można odtworzyć za pomocą ListBox/ListView i tak dalej, również z kontrolkami innych firm, takimi jak ComponentOne, Telerik ...
Jeśli to błąd - czy znasz obejście lub masz dla mnie inne wskazówki?
Oto kod jak ustawić ItemsSource w DataGrid. RowHeightAuto.xaml.cs
public partial class RowHeightAuto : Window
{
private readonly DateTime _start;
public RowHeightAuto()
{
InitializeComponent();
DataGrid1.ItemsSource = GetTestData();
_start = DateTime.Now;
Dispatcher.BeginInvoke(new Action(() => MessageBox.Show((DateTime.Now - _start).TotalSeconds.ToString(CultureInfo.InvariantCulture))), DispatcherPriority.ContextIdle, null);
}
public static List<TestData> GetTestData()
{
const int maxCols = 501;
const int maxRows = 300;
var testDatas = new List<TestData>(maxRows);
for (int i = 0; i < maxRows; i++)
testDatas.Add(new TestData());
for (int i = 0; i < maxCols; i++)
{
string propName = string.Format("Property{0}", AddLeadingZeros(i));
for (int j = 0; j < 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; }
}
+1 za przyzwoicie sformatowane i udokumentowane pierwsze pytanie.Witaj w SO :) – Viv
Proszę, nie możesz napisać 'string.Format (" Property {0: 000} ", i)' zamiast wywoływać metodę 'AddLeadingZeros'. – Clemens
@ Viv: Dzięki. :) @ Clemens: Dzięki za wejście. Jestem noobem z formatami ciągów. :) –