我相信你可以擴展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 –
在這種情況下,附加屬性是你的朋友。請看我更新的答案。 –
感謝這是好多了,我想一個更好的方法來解決這個問題 –