因为下面代码中的文本框和下拉框没有设置'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
};

这样就可以在下拉框中输入值了。

WPF Grid 中 TextBox 和 ComboBox 无法输入值的解决方法

原文地址: https://www.cveoy.top/t/topic/knp0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录