Reputation: 7030
<UserControl x:Class="DDCUI.CommDiagnosisWPFCtrl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Height="950" Width="300">
<DockPanel LastChildFill="True">
<DataGrid DockPanel.Dock="Top" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Height="300" AutoGenerateColumns="False" Name="DGComm" CanUserResizeColumns="True" IsReadOnly="True" SelectedCellsChanged="DGComm_SelectedCellsChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="No." Binding="{Binding Number}" Width="0.1*"/>
<DataGridTextColumn Header="Time" Binding="{Binding Time}" Width="0.1*" />
<DataGridTextColumn Header="Protocol" Binding="{Binding Protocol}" Width="0.15*" />
<DataGridTextColumn Header="Source" Binding="{Binding Source}" Width="0.15*" />
<DataGridTextColumn Header="Destination" Binding="{Binding Destination}" Width="0.15*" />
<DataGridTextColumn Header="Data" Binding="{Binding Data}" Width="0.5*" />
</DataGrid.Columns>
</DataGrid>
<TreeView DockPanel.Dock="Top" MinHeight="200" Name="TreeViewDecode"/>
<RichTextBox Name="RtbHexCode"/>
</DockPanel>
</UserControl>
For some reason, MaxHeight property of the DataGrid is not working. That is, whenever I bind a large table to it, it always overflows and hides the RichTextBox and TreeView (When in reality it shouldn't extend beyond 600 pixels and show a vertical scroll bar).
Also DataGrid doesn't show horizontal scroll bar.
How can I fix this issue?
Edit: Updated code. The MaxHeight property works now but horizontal scrollbar doesnt show
Upvotes: 1
Views: 4655
Reputation: 1140
Add the following to your DataGrid
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
Also replace the StackPanel with a DockPanel or a Grid. StackPanel is not a constrained container.
Upvotes: 3
Reputation: 12295
Height of your Window must be atleast 950 or set the MaxHeight of your Datagrid equal to 450 or set SizeToContent of your Window equal to WidthAndHeight. I hope this will help.
Upvotes: 0