当窗口最大化或恢复时,在WPF中自动化Richtextbox [英] Autoresizing Richtextbox in WPF when Window is Maximized or restored

查看:124
本文介绍了当窗口最大化或恢复时,在WPF中自动化Richtextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我很难在窗体最大化或恢复时尝试调整richtextbox控件的大小。我试图保持控制停靠在一定的宽度,但与网格区域一样高,无论窗口的大小。因此,只要窗口大小发生变化,控件就会根据窗口中的更改来更改高度/宽度。我还在richtextbox的右边有控件,这就是为什么我试图保持一定的宽度,同时停靠在窗体的左侧。

我是WPF的新手,但是知道一点C#,这就是我在做的事情。这主要是帮助我学会更好地使用WPF和C#...

解决方案

嗨迈克尔

试试这个XAML


< Window x:Class =" WpfApplication73.Window1" 

xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml"

Title =" Window1"高度= QUOT; 300"宽度= QUOT; 300">

< Grid>

< Grid.ColumnDefinitions>

< ColumnDefinition Width =" 144" />

< ColumnDefinition Width =" 134 *" />

< /Grid.ColumnDefinitions>

< RichTextBox Background =" Beige"余量= QUOT; 12,12,15,12"名称= QUOT; richTextBox1"宽度= QUOT; 117" />

< / Grid>

< / Window>


如果您将此XAML放入Visual Studio 2008中WPF设计器中的新WPF项目中的window1.xaml并选择设计图面上的RichTextBox通过点击它,您应该看到米色的RichTextBox周围有四个小箭头 - 这些被称为装饰器。它们显示控件停靠在它所在的网格单元格中。这些箭头也可以实时点击 - 单击它们并在不同的设置中运行应用程序。如果在执行此操作时观察XAML窗格,您将看到它们影响富文本框与其容器的对齐,这决定了调整大小时的停靠行为。

我也使用Grid列来控制RichTextBox的宽度 - 我可以把这个固定的宽度放在RichTextBox元素本身上,但是这个方法让我把其他控件放在同一列并控制他们的宽度也一样。第二列是星号,这意味着它占据了网格中水平空间的剩余部分。如果您使用Tables进行基于Web的布局,则此行为与HTML TABLE元素类似。

请告诉我这是否对您有意义 - 我很乐意进一步讨论,

马克


Hello,

Im having trouble trying to figure out resizing the richtextbox control whenever the form is maximized or restored. Im trying to keep the control docked to a certain width, but as tall as the grid area no matter the size of the window. So whenever the window size changes, the control changes height/width depending on which changed in the window. I also have controls to the right of the richtextbox, which is why im trying to keep it a certain width, while docked to the left side of the form.

Im sort of new to WPF, but a know a little C#, which is what Im doing this in. This is mainly something to help me learn to use WPF and C# better...

解决方案

Hi Michael

Try this XAML

<Window x:Class="WpfApplication73.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Height="300" Width="300">

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="144" />

            <ColumnDefinition Width="134*" />

        </Grid.ColumnDefinitions>

        <RichTextBox Background="Beige" Margin="12,12,15,12" Name="richTextBox1" Width="117" />

    </Grid>

</Window>

If you put this XAML into your window1.xaml in a new WPF project in the WPF Designer in Visual Studio 2008 and select the RichTextBox on the design surface by clicking on it, you should see that the beige RichTextBox has four small arrows around it - these are called adorners. They show the control is docked to the grid cell it is in. These arrows are also live-clickable - play around with clicking them and run the app with them in different settings.  If you watch the XAML pane when you do this, you'll see that they affect the alignment of the rich text box to its container, which determines the docking behavior on resize.

I've also used Grid columns to control the width of the RichTextBox - I could have put this fixed width on the RichTextBox element itself, but this method lets me put other controls in the same column and control their width the same way too. The second column is star sized which means it takes up the remainde of horizontal space in the Grid. This behavior is analagous to the HTML TABLE element, if you've ever done web based layout using Tables.

Let me know if this makes sense to you - I'm happy to discuss further,

Mark


这篇关于当窗口最大化或恢复时,在WPF中自动化Richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆