从最近2天起,我陷入一个小问题,我不知道为什么我无法解决它。我做了大量的工作,并实现了堆栈溢出提供的各种建议来解决问题,但最后我因执行不成功而感到厌倦。
我的问题是我想要一个可滚动的数据网格,它可以放在Grid控件或DockPanel中(正如我曾经尝试过的那样)。以下是我正在使用的代码。
<Grid IsEnabled="{Binding IsCalcVarGridPartEnable}">
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="boolToVisiblityConverter" />
<sys.converters:BoolToVisibleHiddenConvertor x:Key="boolToVisibleHiddenConvertor"/>
<FrameworkElement x:Key="ProxyElement"
DataContext="{Binding}"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Border Style="{StaticResource SeperatorStyle}" Grid.Row="0">
<TextBlock Style="{StaticResource BannerTextStyle}" Text="Calculation Variable" />
</Border>
<Border Style="{StaticResource SeperatorStyle}" Grid.Row="2">
<Button Content="Edit" HorizontalAlignment="Right" Margin="10,5" Command="{Binding EditCalcVarCmd}" />
</Border>
<ContentControl Visibility="Collapsed"
Content="{StaticResource ProxyElement}"/>
<DataGrid AutoGenerateColumns="False"
Name="dataGridCalcVar"
VerticalAlignment="Top"
HorizontalAlignment="Left"
IsReadOnly="True"
SelectionMode="Single"
SelectionUnit="FullRow"
ItemsSource="{Binding CalcVarCollection}"
SelectedItem="{Binding SelectedCalcVar}"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick" >
<i:InvokeCommandAction Command="{Binding CalcVarDoubleClickedCmd}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.ColumnHeaderStyle>
<StaticResourceExtension ResourceKey="DataGridColumnHeaderStyle" />
</DataGrid.ColumnHeaderStyle>
<DataGrid.CellStyle>
<StaticResourceExtension ResourceKey="DataGridCellStyle" />
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Type Description" MinWidth="150" MaxWidth="200" Binding="{Binding CalcTypName}" />
<DataGridTextColumn Header="Variable Description" MinWidth="150" MaxWidth="200" Binding="{Binding CalcVarName}" />
<DataGridTextColumn Header="Major Description" MinWidth="150" MaxWidth="200" Binding="{Binding MjAcctTypDesc}"
Visibility="{Binding DataContext.IsMjMiAcctTypVisible, Source={StaticResource ProxyElement},
Converter={StaticResource boolToVisibleHiddenConvertor}}" />
<DataGridTextColumn Header="Minor Description" MinWidth="150" MaxWidth="200" Binding="{Binding MiAcctTypDesc}"
Visibility="{Binding DataContext.IsMjMiAcctTypVisible, Source={StaticResource ProxyElement},
Converter={StaticResource boolToVisibleHiddenConvertor}}" />
<DataGridTextColumn Header="DNA Value" MinWidth="50" MaxWidth="200" Binding="{Binding CalcVarValueName}" />
<DataGridTextColumn Header="Critical Value" MinWidth="50" MaxWidth="200" Binding="{Binding CriticalValueName}" />
<DataGridTextColumn Header="Note" MinWidth="150" MaxWidth="200" Binding="{Binding Note}" />
</DataGrid.Columns>
</DataGrid>
<sysclient:PartStatusView Grid.RowSpan="5" Grid.ColumnSpan="7"
Style="{DynamicResource PartStatusViewDefaultStyle}" IsTabStop="False"/>
</Grid>
重要提示:我只能在设置Datagrid控件的最大高度时获取滚动条,但我不想设置行或数据网格控件的max-height属性。我希望当我调整窗口大小或任何可用空间时,datagrid被设置到该空间中,当我们查询数据时,如果数据数据大于可用空间,则数据网格会带来垂直滚动条。
请帮帮我!!!!!
我希望我能够解释我的问题。 :-): - )
谢谢,
答案 0 :(得分:0)
从我所看到的有两个属性可以帮助你
将Grid.Row="1"
添加到数据网格
从同一个中移除VerticalAlignment="Top"
,实际上阻止它从容器中取出高度
例如
<DataGrid AutoGenerateColumns="False"
Name="dataGridCalcVar"
Grid.Row="1"
HorizontalAlignment="Left"
IsReadOnly="True"
SelectionMode="Single"
SelectionUnit="FullRow"
ItemsSource="{Binding CalcVarCollection}"
SelectedItem="{Binding SelectedCalcVar}"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
我假设你想把网格放在占据剩余空间的中间行。