最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - WPF window status bar disappears when window is sized smaller - Stack Overflow

programmeradmin3浏览0评论

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=";
        xmlns:x=";
        xmlns:d=";
        xmlns:mc=";
        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

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

Thanks for any suggestions.

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/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats./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

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

Thanks for any suggestions.

Share Improve this question asked Feb 14 at 23:21 whitelinedwhitelined 3405 silver badges14 bronze badges 4
  • 1 Have you tried swapping TabControl and StatusBar in Xaml? – emoacht Commented Feb 14 at 23:34
  • I gave it a go, and you know what it works :) When I've worked in HTML so much in the past, this doesn't make that much sense. Anyhow, Cheers. Any idea how to make sure the DataGrid stretches fully withing the tab and adds scroll bars when needed? – whitelined Commented Feb 14 at 23:47
  • 3 Use Grid and RowDefinitions (* for TabControl, Auto for StatusBar). It is very basic of WPF. – emoacht Commented Feb 15 at 0:29
  • 1 Remove DockPanel.Dock from TabControl and keep it as the last child. Read learn.microsoft/en-us/dotnet/api/… – Sir Rufo Commented Feb 15 at 4:01
Add a comment  | 

1 Answer 1

Reset to default 1
<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.

发布评论

评论列表(0)

  1. 暂无评论