我相信你可以扩展TextBox控件使其具有可聚焦性。见this post。
附加属性
public class Ex
{
public static bool GetIsTabStop(DependencyObject obj)
{
return (bool)obj.GetValue(IsTabStopProperty);
}
public static void SetIsTabStop(DependencyObject obj, bool value)
{
obj.SetValue(IsTabStopProperty, value);
}
// Using a DependencyProperty as the backing store for IsTabStop. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsTabStopProperty =
DependencyProperty.RegisterAttached("IsTabStop", typeof(bool), typeof(Ex), new PropertyMetadata(true, Callback));
private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as Control;
if (control != null)
{
control.IsTabStop = (bool)e.NewValue;
control.MouseLeftButtonDown += (sender, args) =>
{
if (!control.IsTabStop)
{
control.IsTabStop = true;
control.Focus();
control.IsTabStop = false;
}
};
}
}
}
XAML
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Margin="215,49,0,0" RenderTransformOrigin="0,7.25"/>
<TextBox HorizontalAlignment="Left" local:Ex.IsTabStop="False" TextWrapping="Wrap" Text="TextBox" Margin="215,96,0,0" VerticalAlignment="Top"/>
<RadioButton Content="RadioButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="210,144,0,0"/>
<RadioButton Content="RadioButton" local:Ex.IsTabStop="False" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="213,183,0,0"/>
基本上可以附加这这是一个从Control继承任何东西。
gahh多数民众赞成soo hackish。我也得到了单选按钮,更多的黑客公司..感谢链接+1 –
在这种情况下,附加属性是你的朋友。请看我更新的答案。 –
感谢这是好多了,我想一个更好的方法来解决这个问题 –