【发布时间】:2016-02-16 10:34:47
【问题描述】:
WPF 专注让我抓狂:(
在一个全新的测试 WPF 项目中,我有这个窗口...
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" x:Name="txtStatic" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<StackPanel Grid.Column="1" Focusable="False">
<Border BorderBrush="LightGray" BorderThickness="0 0 1 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Focusable="False">
<ContentControl x:Name="con" />
</Border>
</StackPanel>
</Grid>
</Window>
还有这个代码隐藏...
Class MainWindow
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim txt As New TextBox
txt.Name = "txtDynamic"
Me.con.Content = txt
txt.Focus()
End Sub
End Class
两个问题...
当上面的项目启动并显示主窗口时,为什么我不能开始在运行时创建的文本框(txtDynamic)中输入?看起来它已经有了焦点。
1234563为什么会这样?
提前致谢。
【问题讨论】: