whitelined
whitelined

Reputation: 350

WPF window status bar disappears when window is sized smaller

I've been playing around with c# and WPF for about 3 weeks now trying to create a plugin to get things done faster in Revit. I've solved most problems by myself, but this one I could really do with some help. So I have this WPF window that will have a few tabs, one to select things, others to set settings and print, etc. The default window size works for my example file, but when I resize it, the DataGrid does not resize with the table, and If I make the window smaller the status bar will disappear. Also, the DataGrid could do with scrollbars.

<Window x:Class="BDS.JustPrintMainWindow"
        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:local="clr-namespace:BDS"
        mc:Ignorable="d"
        Title="Just Print" Height="388" Width="878">
    <DockPanel>
        <TabControl DockPanel.Dock="Top">
            <TabItem Header="Select Sheets/Views" Margin="-2,0,-2,-2">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <WrapPanel Grid.Row="0">
                        <RadioButton Margin="5,5,5,5" IsChecked="True">
                            Views
                        </RadioButton>
                        <RadioButton Margin="5,5,5,5">
                            Sheets
                        </RadioButton>
                    </WrapPanel>
                    <DataGrid Name="uiViewDisplay" Grid.Row="1" SelectionUnit="FullRow" SelectionMode="Extended"  Loaded="OnGridLoad">
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="Select">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}, Mode=TwoWay}" IsHitTestVisible="False"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Print Settings" Margin="-2,0,-2,-2">
            </TabItem>
        </TabControl>
        <StatusBar DockPanel.Dock="Bottom" Height="20" VerticalAlignment="Bottom">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem Grid.Column="0">
                <TextBlock>Sheets Selected</TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="1"/>
            <StatusBarItem Grid.Column="2">
                <TextBlock>Views Selected</TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="3"/>
            <StatusBarItem Grid.Column="4">
                <ProgressBar Value="70" Width="90" Height="20"/>
            </StatusBarItem>
        </StatusBar>
    </DockPanel>
</Window>

This is like the default opening position, which is almost perfect

How I want it to look

And when I shrink the window, status bar has disappeared - and the data grid could do with scroll bars.

enter image description here

Thanks for any suggestions.

Upvotes: 0

Views: 64

Answers (1)

Krugs
Krugs

Reputation: 87

<Grid>
   <Grid.RowDefinitions>
       <RowDefinition Height="*"/>
       <RowDefinition Height="Auto"/>
   <Grid.RowDefinitions>

   <DataGrid Grid.Row="0"/>
   <StatusBar Grid.Row="1"/>

<Grid>

Use a Grid instead of a DockPanel. Then, define the Grid.Row attached property to your DataGrid and StatusBar accordingly.

If you need a powerful table that can display complex data, or support complex data operations, I suggest looking at the Data Grid made by DevExpress.

Upvotes: 1

Related Questions