My colleague has written a user control where he's put in a DataGrid to show a collection of data. (I'd rather use a listbox, but we've been instructed to use DataGrids.) The problem with it is (a) it was fixed at 350 pixels/units height, so when the user
maximized the window it looked kinda funny; and (b) the vertical scrollbar only appeared with the arrow at the top. You couldn't get to the bottom of the list.
So I started working on trying to improve it. I thought it would be a good idea to put the DataGrid into a layout Grid control, which is what I did. But now something else has gone wrong and I haven't a clue as to what. When running it the user control comes
up with the stack panel at the top above the DataGrid. But the DataGrid doesn't show up at all and I can't interact with the user control at all. Even clicking on the close button to the window hosting the user control with the DataGrid in it, is useless.
It does nothing.
Why am I seeing this behavior? Here's the XAML:
<UserControl x:Class="CoreFramework.View.CustomerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:CoreFramework.UserControls"
xmlns:converter="clr-namespace:CoreFramework.ValueConverters"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
xmlns:ignore="http://www.galasoft.ch/ignore"
mc:Ignorable="d ignore" Loaded="UserControl_Loaded"><UserControl.Resources><converter:RequiredFieldConverter x:Key="requiredConverter" /></UserControl.Resources><Grid><Grid.RowDefinitions><RowDefinition Height="auto"/><RowDefinition Height="*" /></Grid.RowDefinitions><StackPanel MinWidth="200"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="8*" /><ColumnDefinition Width="auto" /></Grid.ColumnDefinitions><TextBlock Text="{Binding TableHeader, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource Heading2}" /><Menu Grid.Column="1" FontSize="10.667" Background="{x:Null}"><MenuItem Header="SETTINGS" Background="{x:Null}" Foreground="#FF706C6C" Command="{Binding ViewSettingsCommand}" Click="MenuItem_Click"/><MenuItem Header="|" Background="{x:Null}" Foreground="#FFD1CFCF" IsEnabled="False" IsHitTestVisible="False" /><MenuItem Header="HELP" Background="{x:Null}" Foreground="#FF706C6C" Command="{Binding ViewHelpCommand}" /></Menu></Grid><uc:CoreToolbar /></StackPanel><TabControl x:Name="ViewPort"
Margin="0,0,0,0"
BorderThickness="0"
Grid.Row="1"
SelectedIndex="{Binding ViewIndex, Mode=OneWay,UpdateSourceTrigger=PropertyChanged, IsAsync=True}" Background="Transparent" ><TabControl.Resources><Style TargetType="TabItem"><Setter Property="Template" ><Setter.Value><ControlTemplate TargetType="TabItem" /></Setter.Value></Setter></Style></TabControl.Resources><TabItem Header="Summary"><Grid><Grid.RowDefinitions><RowDefinition MinHeight="350" /></Grid.RowDefinitions><DataGrid Name="dataGrid"
ItemsSource="{Binding Rows}"
SelectedItem="{Binding SelectedRow, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="True"
VerticalScrollBarVisibility="Visible"
IsSynchronizedWithCurrentItem="True" AutoGeneratingColumn="dataGrid_AutoGeneratingColumn"><DataGrid.ContextMenu><ContextMenu><MenuItem Header="Show All" Icon="{StaticResource ShowAllImage}" Command="{Binding ShowAllCommand}"/><MenuItem Header="Omit Set" Icon="{StaticResource OmitImage}" Command="{Binding OmitSetCommand}"/><MenuItem Header="Establish Set" Icon="{StaticResource EstablishImage}" Command="{Binding EstablishSetCommand}"/><MenuItem Header="Recall Set" Icon="{StaticResource RecallImage}" Command="{Binding RecallSetCommand}"/><MenuItem Header="Merge Sets" Icon="{StaticResource MergeImage}" Command="{Binding MergeSetCommand}"/></ContextMenu></DataGrid.ContextMenu><i:Interaction.Triggers><i:EventTrigger EventName="MouseDoubleClick"><i:InvokeCommandAction Command="{Binding EditItemCommand}" /></i:EventTrigger><i:EventTrigger EventName="SelectionChanged"><cmd:EventToCommand Command="{Binding SelectionChangedEventCommand}"
PassEventArgsToCommand="True"
CommandParameter="{Binding SelectedItems, ElementName=dataGrid}" /></i:EventTrigger></i:Interaction.Triggers></DataGrid></Grid></TabItem><TabItem Header="Detail"><Grid Style="{StaticResource ContentTop}"><ScrollViewer><StackPanel MinWidth="200"><StackPanel x:Name="Column1" Orientation="Vertical" Grid.Column="0"><StackPanel.Resources><Style TargetType="{x:Type TextBox}"><Setter Property="Margin" Value="3" /><Setter Property="HorizontalAlignment" Value="Left"/></Style><Style TargetType="{x:Type TextBlock}"><Setter Property="Margin" Value="3" /><Setter Property="Height" Value="23" /><Setter Property="FontWeight" Value="Bold" /><Setter Property="VerticalAlignment" Value="Center" /></Style></StackPanel.Resources><Grid HorizontalAlignment="Left" ><Grid.ColumnDefinitions><ColumnDefinition Width="auto" /><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="auto" /></Grid.RowDefinitions><StackPanel Orientation="Vertical" Margin="0,4,0,0"><TextBlock Text="ID " TextDecorations="{Binding Customer.ID, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|ID}"/><TextBlock Text="Extension " TextDecorations="{Binding Customer.Extension, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Extension}"/><TextBlock Text="Fax " TextDecorations="{Binding Customer.Fax, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Fax}"/><TextBlock Text="Phone " TextDecorations="{Binding Customer.Phone, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Phone}"/><TextBlock Text="Shipping Address " TextDecorations="{Binding Customer.Shipping_Addr1, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Shipping_Addr1}"/><TextBlock Text=" " /><TextBlock Text="Shipping City " TextDecorations="{Binding Customer.Shipping_City, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Shipping_City}" /><TextBlock Text="Shipping State " TextDecorations="{Binding Customer.Shipping_State, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Shipping_State}" /><TextBlock Text="Shipping Zipcode " TextDecorations="{Binding Customer.Billing_Zip, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Billing_Zip}" /><TextBlock Text="Billing Address " TextDecorations="{Binding Customer.Billing_Addr1, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Billing_Addr1}" /><TextBlock Text=" " /><TextBlock Text="Billing City " TextDecorations="{Binding Customer.Billing_City, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Billing_City}"/><TextBlock Text="Billing State " TextDecorations="{Binding Customer.Billing_State, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Billing_State}"/><TextBlock Text="Billing Zipcode " TextDecorations="{Binding Customer.Billing_Zip, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Billing_Zip}"/><TextBlock Text="Comments " TextDecorations="{Binding Customer.Comments, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Comments}"/><TextBlock Text="Company Name " TextDecorations="{Binding Customer.Company_Name, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Company_Name}" /><TextBlock Text="Contact Name " TextDecorations="{Binding Customer.Contact_Name, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Contact_Name}"/><TextBlock Text="Email " TextDecorations="{Binding Customer.Email, Converter={StaticResource requiredConverter}, ConverterParameter=Customer|Email}"/></StackPanel><StackPanel Orientation="Vertical" Grid.Column="1" HorizontalAlignment="Left"><TextBox x:Name="txtID" Width="150" Text="{Binding Path=Customer.ID}" IsReadOnly="True" /><TextBox x:Name="txtExtension" Width="250" Text="{Binding Path=Customer.Extension}" /><TextBox x:Name="txtFax" Width="250" Text="{Binding Path=Customer.Fax}" /><TextBox x:Name="txtPhone" Width="250" Text="{Binding Path=Customer.Phone}" /><TextBox x:Name="txtShipping_Addr1" Width="250" Text="{Binding Path=Customer.Shipping_Addr1}" /><TextBox x:Name="txtShipping_Addr2" Width="250" Text="{Binding Path=Customer.Shipping_Addr2}" /><TextBox x:Name="txtShipping_City" Width="250" Text="{Binding Path=Customer.Shipping_City}" /><TextBox x:Name="txtShipping_State" Width="250" Text="{Binding Path=Customer.Shipping_State}" /><TextBox x:Name="txtShipping_Zip" Width="250" Text="{Binding Path=Customer.Shipping_Zip}" /><TextBox x:Name="txtBilling_Addr1" Width="250" Text="{Binding Path=Customer.Billing_Addr1}" /><TextBox x:Name="txtBilling_Addr2" Width="250" Text="{Binding Path=Customer.Billing_Addr2}" /><TextBox x:Name="txtBilling_City" Width="250" Text="{Binding Path=Customer.Billing_City}" /><TextBox x:Name="txtBilling_State" Width="250" Text="{Binding Path=Customer.Billing_State}" /><TextBox x:Name="txtBilling_Zip" Width="250" Text="{Binding Path=Customer.Billing_Zip}" /><TextBox x:Name="txtComments" Width="400" Text="{Binding Path=Customer.Comments}" /><TextBox x:Name="txtCompany_Name" Width="250" Text="{Binding Path=Customer.Company_Name}" /><TextBox x:Name="txtContact_Name" Width="250" Text="{Binding Path=Customer.Contact_Name}" /><TextBox x:Name="txtEmail" Width="250" Text="{Binding Path=Customer.Email}" /></StackPanel></Grid></StackPanel></StackPanel></ScrollViewer></Grid></TabItem></TabControl></Grid></UserControl>
Rod