我在Silverlight布局引擎中发现了一个错误(?!),但可能是我的错误使用...
错误如下: 切换到标签“B”,观察第一个错误: - 左上方数据网格中没有滚动条可见性 在两个上部网格中向下滚动一下,更改为Tab“A”,然后再转到Tab“B”,观察: - 左上角网格:将滚动位置重置为顶部
这两个错误都可以通过以下任一步骤来解决: - 使第1行高度固定(*或固定像素高度) - 使第0列宽度固定
现在为示例代码,首先是MainPage.xaml:
<Grid x:Name="LayoutRoot" Background="White">
<sdk:TabControl >
<sdk:TabItem Header="A" >
</sdk:TabItem>
<sdk:TabItem Header="B" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<sdk:DataGrid ItemsSource="{Binding LotsOfItems1}" Grid.Row="0" Grid.Column="0"/>
<sdk:DataGrid ItemsSource="{Binding LotsOfItems2}" Grid.Row="0" Grid.Column="1"/>
<sdk:DataGrid ItemsSource="{Binding SomeItems}" Grid.Row="1" Grid.ColumnSpan="2" />
</Grid>
</sdk:TabItem>
</sdk:TabControl>
</Grid>
</UserControl>
现在是代码隐藏(MainPage.xaml.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace TabDataGridScrollProblem
{
public class ItemClass1
{
public string PropA { get; set; }
public string PropB { get; set; }
}
public class ItemClass2
{
public string PropA { get; set; }
public string PropB { get; set; }
public string PropC { get; set; }
public string PropD { get; set; }
}
public class ItemClass3
{
public string PropA { get; set; }
public string PropB { get; set; }
public string PropC { get; set; }
public string PropD { get; set; }
public string PropE { get; set; }
public string PropF { get; set; }
public string PropG { get; set; }
}
public class DataClass
{
public ItemClass1[] LotsOfItems1 { get; set; }
public ItemClass2[] LotsOfItems2 { get; set; }
public ItemClass3[] SomeItems { get; set; }
}
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.DataContext = new DataClass()
{
LotsOfItems1 = Enumerable.Range(0, 100).Select(x => new ItemClass1()
{
PropA = "Aha " + x,
PropB = "SOSO " + x,
}
).ToArray(),
LotsOfItems2 = Enumerable.Range(0, 100).Select(x => new ItemClass2()
{
PropA = "Aha " + x,
PropB = "SOSO " + x,
PropC = "CCCha " + x,
PropD = "DDDOSO " + x,
}
).ToArray(),
SomeItems = Enumerable.Range(0, 3).Select(x => new ItemClass3()
{
PropA = "Aha " + x,
PropB = "SOSO " + x,
PropC = "CCCha " + x,
PropD = "DDDOSO " + x,
PropE = "SOSO " + x,
PropF = "CCCha " + x,
PropG = "DDDOSO " + x,
}
).ToArray(),
};
}
}
}
此致 约翰内斯
P.S .: 我在WPF(.Net 4.0)中尝试了相同的代码 - 并且只观察到滚动条不可见的错误(滚动位置被保留!)
P.P.S .: 切换标签需要很长时间 - 布局引擎似乎很难......
P.P.P.S。:(抱歉,现在调查自己......) 解决问题的另一种方法:将上部网格包装在另一个网格中 - 因此Tab“B”的内容如下所示: <sdk:TabItem Header="B" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<sdk:DataGrid ItemsSource="{Binding LotsOfItems1}" Grid.Row="0" Grid.Column="0"/>
<sdk:DataGrid ItemsSource="{Binding LotsOfItems2}" Grid.Row="0" Grid.Column="1"/>
</Grid>
<sdk:DataGrid ItemsSource="{Binding SomeItems}" Grid.Row="1" />
</Grid>
</sdk:TabItem>