DockPanel调整大小和TextBox换行符

时间:2011-03-14 17:47:05

标签: c# wpf treeview textbox dockpanel

我有一个带有两个网格的DockPanel(DockPanel.Dock =“右/左”)。在左边我有一个TreeView,在右边我有一些TextBoxes。如果我调整窗口大小,面板会按比例调整大小。

我的问题是,如果我在TextBox中写长文本,TextBox会放大并隐藏我的左侧DockPanel而不是中断文本。

我已将左侧DockPanel的minwidth设置为“300”,并将TextBoxes中的TextWrapping设置为“wrap”但没有任何帮助。

来源:

 <Grid Background="#FF58ACFC" Name="main">
    <DockPanel>
       <Grid DockPanel.Dock="Right" Margin="0,0,5,0">

            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="200" />                    
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="26"/>
                <RowDefinition Height="26"/>
                <RowDefinition Height="26"/>
                <RowDefinition Height="60" />
                <RowDefinition Height="26"/>
                <RowDefinition />
            </Grid.RowDefinitions>

            <Label Content="Titel:" Grid.Row="0"/>
            <TextBox Grid.Row="1" IsReadOnly="False">

            <Label Content="Frage:" Grid.Row="2"/>
            <TextBox Grid.Row="3" TextWrapping="Wrap" IsReadOnly="False" AcceptsReturn="True">

            <Label Content="Antwort:" Grid.Row="4"/>
            <TextBox Grid.Row="5" IsReadOnly="False" TextWrapping="Wrap" />
        </Grid>


        <Grid DockPanel.Dock="Left" Margin="5,0,0,0">

            <DockPanel>
                <Grid DockPanel.Dock="Left">
                    <DockPanel LastChildFill="True">
                        <Grid DockPanel.Dock="Top" Height="26">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Label Content="Kategorie" Grid.Column="0"/>
                            <Button Grid.Column="1" BorderThickness="0" HorizontalAlignment="Right">
                        </Grid>

                        <TreeView HorizontalAlignment="Stretch" VerticalAlignment="Stretch"Padding="0,0,15,0" />
                    </DockPanel>
                </Grid>

                <Grid DockPanel.Dock="Right">
                    <DockPanel LastChildFill="True">

                        <Grid DockPanel.Dock="Top" Height="26">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <Label Content="Lernkarten" Grid.Column="0"/>
                            <Button Grid.Column="1" Width="26" Click="ButtonAddItem_Click">
                        </Grid>

                        <ListView />
                    </DockPanel>
                </Grid>
            </DockPanel>
        </Grid>
    </DockPanel>
</Grid>

1 个答案:

答案 0 :(得分:2)

这就是Dockpanels无用的原因: - )

我建议使用Grid ..