为啥下面代码创建的文本框和下拉框不能输入值 Grid grid = new Grid;gridRowDefinitionsAddnew RowDefinition Height = new GridLength70 ;gridRowDefinitionsAddnew RowDefinition Height = GridLengthAuto ;gridRowDefinitionsAddnew
因为下面代码中的文本框和下拉框没有设置IsReadOnly属性为false,所以不能输入值:
var text = new TextBox() { Margin = new Thickness(0, 5, 0, 5), FontSize = 17, Foreground = Brushes.Blue, VerticalAlignment = VerticalAlignment.Center, Width = 80 };
要使其能够输入值,需要添加IsReadOnly属性的设置:
var text = new TextBox() { Margin = new Thickness(0, 5, 0, 5), FontSize = 17, Foreground = Brushes.Blue, VerticalAlignment = VerticalAlignment.Center, Width = 80, IsReadOnly = false };
对于下拉框,需要使用ComboBox控件,同样需要设置IsEditable属性为true,才能输入值:
var comboBox = new ComboBox() { Margin = new Thickness(0, 5, 0, 5), FontSize = 17, Foreground = Brushes.Blue, VerticalAlignment = VerticalAlignment.Center, Width = 80, IsEditable = true };
这样就可以在下拉框中输入值了
原文地址: https://www.cveoy.top/t/topic/cZzR 著作权归作者所有。请勿转载和采集!