如果我有一个窗口的UI来自控件模板,则显示键盘焦点的虚线(“焦点视觉”)不显示。如果我使用直接内容而不是控件模板来实现,那么焦点视觉效果很好。没有显示带控制模板窗口的焦点虚线
任何人都知道如何使用控件模板时有焦点视觉?
我最初使用XAML,但为了排除它,我在C#中做了演示代码。我也很满意基于XAML的解决方案。
的Class1.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
class Class1 : Window
{
public Class1()
{
Title = "Class1";
Height = 150;
Width = 300;
Template = new ControlTemplate() {
VisualTree = new FrameworkElementFactory(typeof(Template1))
};
}
class Template1 : StackPanel
{
public Template1()
{
Background = Brushes.White;
Children.Add(new TextBox());
Children.Add(new Button() { Content = "button 1" });
Children.Add(new Button() { Content = "button 2" });
}
}
}
Class2.cs
using System.Windows;
using System.Windows.Controls;
class Class2 : Window
{
public Class2()
{
Title = "Class2";
Height = 150;
Width = 300;
Content = new StackPanel
{
Children =
{
new TextBox(),
new Button() { Content = "button 1" },
new Button() { Content = "button 2" },
}
};
}
}
MainWindow.cs
我刚刚推出的自定义窗口从主窗口...
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
(new Class1()).Show();
(new Class2()).Show();
}
}
大答案沙拉达普拉,你明白了吧! –
谢谢!我想知道AdornerDecorator的用途。 – Vimes