wpf-4.0 相关问题

Windows Presentation Foundation(WPF)的4.0版。

如何使我的控件可聚焦?

我有控制 公共类 FocusTestControl :控制 { 公共 FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } 这是它的默认样式 <question vote="0"> <p>我有一个控制</p> <pre><code>public class FocusTestControl : Control { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } </code></pre> <p>这是它的默认样式</p> <pre><code> &lt;Style TargetType=&#34;local:FocusTestControl&#34;&gt; &lt;Setter Property=&#34;Focusable&#34; Value=&#34;True&#34; /&gt; &lt;Setter Property=&#34;Template&#34;&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Grid&gt; &lt;Border Background=&#34;AliceBlue&#34; /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>我将此控件放在窗口上:</p> <pre><code>&lt;Window x:Class=&#34;MakeWpfControlFocusable.MainWindow&#34; xmlns=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34; xmlns:local=&#34;clr-namespace:MakeWpfControlFocusable&#34; Title=&#34;MainWindow&#34; Height=&#34;350&#34; Width=&#34;525&#34;&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height=&#34;35&#34; /&gt; &lt;/Grid.RowDefinitions&gt; &lt;local:FocusTestControl /&gt; &lt;StackPanel Grid.Row=&#34;1&#34; Orientation=&#34;Horizontal&#34;&gt; &lt;TextBlock Text=&#34;Focused element: &#34; /&gt; &lt;TextBlock Text=&#34;{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=KeyboardFocusedElement}&#34; /&gt; &lt;TextBox Text=&#34;Text&#34; /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>但是单击控件并不会使其聚焦(我的意思是 KebordFocus)</p> <p>实际上,我的任务是处理 KeyDown 和 KeyUp 事件。但当元素没有键盘焦点时这是不可能的。</p> </question> <answer tick="true" vote="1"> <p>可以通过按 Tab 键盘键来设置键盘焦点。但点击 <pre><code>Control</code></pre> 时并未设置。我已订阅 <pre><code>MouseDown</code></pre> 事件并在处理程序中手动设置焦点。</p> <pre><code>public class FocusTestControl : Control, IInputElement { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); MouseDown += FocusTestControl_MouseDown; } void FocusTestControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Keyboard.Focus(this); } } </code></pre> </answer> </body></html>

回答 0 投票 0

如何正确处理焦点

假设我有下一个布局: 窗户 用户控制 用户控制 用户控制 按钮 网格控制 网格单元 假设 GridCell 当前具有键盘焦点。 ...

回答 2 投票 0

WPF Datagrid DataGridTextColumn 不允许小数

我无法在 DataGridTextColumn 中输入十进制值。如果 UpdateSourceTrigger = PropertyChanged,下面的链接建议我们不能输入小数值。 WPF DataGridTextColumn 绑定不&...

回答 3 投票 0

WPF将StackPanel的宽度从0设置为自动?

我正在尝试对StackPanel进行动画处理,使其可见性从0的宽度增加到其自动宽度,这是我目前的状态: ] >>

回答 2 投票 6

等同于WPF4中的CompositionInialiser.SatisfyImports(this)?

我是Silverlight程序员,尝试过WPF4。在使用MEF的Silverlight 4中,我们编写了CompositionInialiser.SatisfyImports(this),它允许MEF发现零件并将其插入。什么...

回答 1 投票 0

如何在WPF 4中创建翻转控件?

我是Silverlight开发人员,在Silverlight中我们使用PlanarProjection来创建这样的效果。事实上这是Mike Taulty在Silverlight中的演示项目:http:// ...

回答 1 投票 3

© www.soinside.com 2019 - 2024. All rights reserved.