DockPanel 调整大小和 TextBox 换行

发布于 2024-10-22 01:28:44 字数 3187 浏览 2 评论 0原文

我有一个带有两个网格的 DockPanel (DockPanel.Dock="Right/Left")。左边有一个 TreeView,右边有一些文本框。如果我调整窗口大小,面板将按比例调整大小。

我的问题是,如果我在 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>

I have a DockPanel with two Grids (DockPanel.Dock="Right/Left"). In the left i have a TreeView and in the right i have some TextBoxes. If i resize my window the panels resize proportinal.

My problem is, if i write long text in a TextBox the TextBox enlarge and hide my left DockPanel instead of a break the text.

I have set minwidth of the left DockPanel to '300' and set TextWrapping in the TextBoxes to 'wrap' but nothing helps.

Source:

 <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-10-29 01:28:44

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

我建议使用 Grid..

That's pretty much why Dockpanels are useless :-)

I suggest using Grid..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文