.net WPF TextBox调整为制表控件宽度高度

ldioqlga  于 2023-06-25  发布在  .NET
关注(0)|答案(1)|浏览(117)

大家好,希望有一个简单的答案,我错过了,在应用程序的底部,我想有tabcontrol >标签项的内容重新大小。我只是到目前为止有一个问题的textbox控件没有调整大小到tabcontrol的高度和宽度。谁能解释一下我在这里错过了什么。正如你所看到的,当我展开拆分器时,文本框保持居中。提前感谢您的时间!

<UserControl x:Class="MySqlApp.UI.QueryControl"
         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" 
         xmlns:local="clr-namespace:MySqlApp.UI"
         mc:Ignorable="d" d:DesignWidth="883" d:DesignHeight="648">
<Grid>
    <DockPanel>
        <Menu x:Name="MainMenu" Height="35" HorizontalAlignment="Center" DockPanel.Dock="Top">
            <MenuItem BorderBrush="LightBlue"  BorderThickness="1"  Margin="5" Header="Execute SQL" x:Name="RunSqlScript" Click="Button_RunSqlScript">
                <MenuItem.Icon>
                    <Image Source="../SQLExecute.png"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem IsEnabled="False" x:Name="CancelSQL" BorderBrush="LightBlue"  BorderThickness="1"  Margin="5" Header="Cancel" Click="CancelSQL_Click">
                <MenuItem.Icon>
                    <Image Source="/cancel.png"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem x:Name="OutputReults" Header="Output results to screen" IsCheckable="True" IsChecked="True">
            </MenuItem>
            <MenuItem Header="Select result:"></MenuItem>
            <ComboBox Width="170" Margin="5" x:Name="ResultsComboBox">
            </ComboBox>
            <MenuItem Header="View result"
                      Margin="5" BorderBrush="LightBlue" BorderThickness="1"
                      Click="Button_ViewResult">
                <MenuItem.Icon>
                    <Image Source="../datatable.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem BorderBrush="LightBlue" BorderThickness="1" Margin="5" Header="Export results to file" Click="ExportResult_Click">
                <MenuItem.Icon>
                    <Image Source="../SqlExport.png" />
                </MenuItem.Icon>
            </MenuItem>
        </Menu>
        <Grid Width="5" DockPanel.Dock="Left"></Grid>
        <Grid Width="5" DockPanel.Dock="Right"></Grid>
        <Grid DockPanel.Dock="Bottom"></Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Content="Select a SQL Script or paste a query below" />
            <TextBox Width="500" HorizontalAlignment="Left" Grid.Row="1" x:Name="SqlScriptFilePath" />
            <Button Margin="501,0,0,0" Grid.Row="1" HorizontalAlignment="Left"  Padding="10,0,10,0" Content="..." Click="Button_SelectSqlScript" Width="35" />
            <TextBox VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"  Margin="0,5,0,0" Grid.Row="2" x:Name="SqlStatementText" TextWrapping="NoWrap"  AcceptsReturn="True">
                /*  Example:
                        SELECT TOP(1000) * FROM Member 
                    */
            </TextBox>
            <GridSplitter VerticalAlignment="Center" ShowsPreview="True" Grid.Row="3" HorizontalAlignment="Stretch" Background="#FFACACAC"  Height="5" ResizeDirection="Rows"/>
            <TabControl MinHeight="200" MinWidth="200" x:Name="tabControl" Grid.Row="4">
                <TabItem x:Name="tabOutput">
                    <TabItem.Header>Output</TabItem.Header>
                    <Grid>
                        <TextBox
                                MaxWidth="{Binding ElementName=tabControl, Path=ActualWidth}"
                                MaxHeight="{Binding ElementName=tabControl,Path=ActualHeight}"
                                HorizontalScrollBarVisibility="Visible"
                                VerticalScrollBarVisibility="Visible"
                                Margin="0,5,0,5"
                                Width="auto"
                                VerticalAlignment="Stretch"
                                HorizontalAlignment="Stretch"
                                AcceptsReturn="True"
                                TextWrapping="NoWrap"
                                Visibility="Visible"
                                x:Name="RtbOutput">
                        </TextBox>
                        <local:DataViewControl
                            MaxWidth="{Binding ElementName=tabControl, Path=ActualWidth}"
                            MaxHeight="{Binding ElementName=tabControl,Path=ActualHeight}"
                            Width="auto"
                            Margin="0,5,0,5"
                            HorizontalAlignment="Stretch"    
                            VerticalAlignment="Stretch"
                            Visibility="Hidden"
                            x:Name="DataViewControl" />
                    </Grid>
                </TabItem>
                <TabItem x:Name="tabLog">
                    <TabItem.Header>Log</TabItem.Header>
                    <ListView
                MaxWidth="{Binding ElementName=tabControl, Path=ActualWidth}"
                MaxHeight="{Binding ElementName=tabControl,Path=ActualHeight}"
                Width="auto"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Grid.Row="6" 
                x:Name="ListResults">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Result" Width="300">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Path=Result}" Foreground="{Binding Color}"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Width="130" Header="StartTime" DisplayMemberBinding="{Binding StartTime}" />
                                <GridViewColumn Width="130" Header="EndTime" DisplayMemberBinding="{Binding EndTime}" />
                                <GridViewColumn Width="130" Header="Duration" DisplayMemberBinding="{Binding Duration}" />
                                <GridViewColumn Width="130" Header="Timestamp" DisplayMemberBinding="{Binding Timestamp}"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
                </TabItem>
            </TabControl>
        </Grid>
    </DockPanel>
</Grid>

rqmkfv5c

rqmkfv5c1#

我在后面的代码中添加了一个最大大小到用户控件500,删除了这个值,它是按照预期工作!

相关问题