获取WPF窗体上的控件并赋值 八

获取WPF窗体上的控件并赋值 八

2023年7月19日发(作者:)

获取WPF窗体上的控件并赋值八

using System;

using c;

using ;

using ;

using ;

using s;

using ls;

using ;

using nts;

using ;

using ;

using g;

using tion;

using ;

namespace 获取空间上的textBOX并赋值1

{

/// <summary>

/// 的交互逻辑

/// </summary>

public partial class MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

Start();

}

public void Start()

{

= "张三";

= "18";

= "男";

}

private void btn_Click(object sender, RoutedEventArgs e)

{

Editable(en); //gridUCContent为最顶层Grid

}

private void SetNotEditable(UIElementCollection uiControls) {

foreach (UIElement element in uiControls)

{

if (element is TextBox)

{

(element as TextBox).IsEnabled = false;

= ;

= ;

= ;

}

else if (element is Grid)

{

Editable((element as Grid).Children);

}

else if (element is Expander)

{

//此代码仅供参考

//在您的布局中,Expander或者其他不具有Children属性的控件的Content,若不是StackPanl或Grid,而是其他的子控件,则需要更多的判断

if ((element as Expander).Content is StackPanel)

{

StackPanel sa = (element as Expander).Content as StackPanel;

Editable(en);

}

else if ((element as Expander).Content is Grid)

{

Grid sa = (element as Expander).Content as Grid;

Editable(en);

}

}

else if (element is StackPanel)

{

Editable((element as StackPanel).Children);

}

else if (element is ScrollViewer)

{

StackPanel sp = (element as ScrollViewer).Content as StackPanel;

Editable(en);

//ScrollViewer不具有Children属性,无法对其进行遍历,但是具有Content属性,作为容器型控件,一般都可以通过这样的方法来解决。

}

}

}

}

}

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689721603a281036.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信