在我们的应用程序中,我们使用datagrids来布局填充了模板化内容和按钮的行,但是间歇性地出现问题,其中某些列有时会将自身的大小调整为列的最小宽度,有时会调整到列标题内容宽度.这似乎与设置itemssource的时间和加载事件发生的时间有关,但我无法确定它.
行为不正确的示例

正确行为的示例

itemssource绑定到viewmodel上的ObservableCollection,它使用async和await关键字以及dataservice填充异步.
我试图通过隐藏初始化中的所有列来解决问题,然后一旦设置了itemssource并调用了isloaded,将所有列设置回初始可见性,这似乎有一些影响,但没有完全解决问题.
列定义的xaml
<Style x:Key="MainDataGridColumnHeader" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<TextBlock Text="{TemplateBinding Content}" Foreground="{StaticResource HighlightedTextBrush}"
Background="Transparent"
FontSize="16" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MainDataGridRow" TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="{StaticResource LightBackgroundBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource Faded10MidBackgroundBrush}"/>
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Padding" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True"
CornerRadius="0"
Margin="0,5"
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" …Run Code Online (Sandbox Code Playgroud) 在运行测试时,karma似乎多次复制最后一次测试,测试重复的次数似乎取决于测试的数量和用于运行的浏览器.
如果仅使用一个浏览器(PhantomJS或Chrome)进行一次测试,则测试会显示两次,当使用两种浏览器时,相同的单次测试最多显示6次.
我已经将测试记录添加到测试中,每个浏览器每次测试都会记录一次,因此测试运行的次数可能正确,但只是重复显示的结果.
karma.conf.js
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'_test/test.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter …Run Code Online (Sandbox Code Playgroud)