TextBox无法编辑

时间:2013-08-14 03:11:57

标签: c# wpf

我找到了一个解决方案here,只能在代码中生成表单。

但是当我尝试向面板添加TextBox时,无法进行编辑。

var window = new Window();
var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
stackPanel.Children.Add(new TextBox { Text = "Text" } );
window.Content = stackPanel;

1 个答案:

答案 0 :(得分:1)

我刚试过这个,它运行正常。

private void Test_Click(object sender, RoutedEventArgs e)
{
    var window = new Window();
    var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
    stackPanel.Children.Add(new TextBox { Text = "Text" });
    window.Content = stackPanel;
    window.Show();
}

<Window x:Class="WPF_Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button x:Name="Test" Content="Click Me" Click="Test_Click" />
    </Grid>
</Window>

当您点击主窗口中的按钮时,它会打开一个新窗口,其中包含一个可以编辑的文本框。

相关问题