将控件的大小分配给窗口的大小

将控件的大小分配给窗口的大小

本文介绍了WPF(VS2010)将控件的大小分配给窗口的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai all,

我有一个非常简单的问题。我希望我的RichTextBox的大小与我的主窗口相同。请看看我的代码:

Hai all,
I have a very simple question.I want my RichTextBox to be in the size of my mainwindow.Please have a look at my code:

Class MainWindow


    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        RichTextBox1.Width = Me.Width : RichTextBox1.Height = Me.Height
    End Sub
End Class



他当窗口加载时,一切正常,但是当我最大化它时,文本框的大小不会改变。它的大小保持不变,就像加载时窗口的大小一样。在Winforms中,我曾经修复过通过将其锚点分配到顶部,底部,左侧,右侧。但是在WPF中我找不到这样的属性。任何人请帮我解决我的问题!

提前谢谢!


Her all works fine when the window loads,but when I maximize it the size of the textbox do not change.It''s size remains same that is the the size of the window when it was loaded.In Winforms,I used to fix this by assigning its Anchor to Top,Bottom,Left,Right.But in WPF I don''t find such a property.Anyone kindly please solve my problem!
Thanks in advance!

推荐答案

Private Sub Window_SizeChanged(sender As Object, e As SizeChangedEventArgs)

End Sub


Private Sub MainWindow_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
       If WindowState = WindowState.Maximized Then
           txt.Width = Windows.WindowState.Maximized
           txt.Height = Me.ActualHeight : txt.Width = Me.ActualWidth
       End If

   End Sub



工作正常!


It''s working fine!


这篇关于WPF(VS2010)将控件的大小分配给窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:11