RyB*_*olt 3 xaml silverlight-4.0 uielement
我只看到了这个问题的代码解决方案.我正在寻找一个基于XAML的解决方案,我很安静,你不能把注意力集中在XAML中的UI元素上.
我发现这个旧的MSDN帖子:http://social.msdn.microsoft.com/Forums/en/wpf/thread/09dc837d-4485-4966-b45b-266727bbb90c
有我寻求的解决方案(这只是我猜的WPF)
<Grid FocusManager.FocusedElement="{Binding ElementName=listBox1}">
Run Code Online (Sandbox Code Playgroud)
是否将焦点设置为Silverlight 4 XAML中的TextBox/ListBox ?
如果你足够努力,XAML总会有一种方法.:)你需要的是一个Trigger,来自Blend SDK.
public class FocusTrigger : TargetedTriggerAction<Control>
{
protected override void Invoke(object parameter)
{
if (Target == null)
return;
Target.Focus();
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用它像:
<Button Content="Move focus">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<local:FocusTrigger TargetName="TheTextBox"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBox x:Name="TheTextBox"/>
Run Code Online (Sandbox Code Playgroud)
如果你想获得真正的幻想,你可以在你的触发器中应用一个条件,并在XAML中做各种疯狂的事情.我会说我很惊讶这种东西不是内置的.