wpf编程:stackPanel控件中动态添加子控件问题

wpf编程:stackPanel控件中动态添加子控件问题,第1张

实例代码://在picture1上面添加一个commandbuttonPrivateSubForm_Load()Form1.Controls.Add"VB.CommandButton","cmdOk",Picture1//动态添加控件WithForm1.cmdOk.Visible=True.Width=500.Caption="确认(&Y)"EndWithEndSub

那是你的StackPanel的高度不够了,或者是StackPanel的父级元素高度不够!你可以不设置StackPanel的高度然后给StackPanel套一个Scrollviewer

设置该面板的visibility属性就可以了

假设一个StackPanel控件就是你的主窗口,一个Button控件就是你的图标。

WPF的语句:

<Button Content="展开" Name="Button1" />

<StackPanel Visibility="Collapsed" Name="StackPanel1"/>

如果用C#编程

private void button1_Click(object sender, RoutedEventArgs e)

{

string value

value = button1.Content.ToString()

if (value == "展开")

{

stackPanel1.Visibility = System.Windows.Visibility.Visible

button1.Content = "收起"

}

else if (value == "收起")

{

stackPanel1.Visibility = System.Windows.Visibility.Collapsed

button1.Content = "展开"

}

}

如果用VB.NET编程

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

If Button1.Content = "展开" Then

StackPanel1.Visibility = Windows.Visibility.Visible

Button1.Content = "收起"

ElseIf Button1.Content = "收起" Then

StackPanel1.Visibility = Windows.Visibility.Collapsed

Button1.Content = "展开"

End If

End Sub

希望能够帮到你!!!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7973912.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存