Windows7、Visual Studio 2013、WPFで開発しています。
現在focusしているobjectを取得したいです。
XAML
1<Window x:Class="WpfApplication6.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="350" Width="525"> 5 <StackPanel Name="panel" FocusManager.IsFocusScope="True"> 6 <Rectangle Name="rectangle1" Focusable="True" Fill="#FFF4F4F5" Height="100" Stroke="Black" MouseUp="Rectangle_MouseUp"/> 7 <Rectangle Name="rectangle2" Focusable="True" Fill="#FFF4F4F5" Height="100" Stroke="Black" MouseUp="Rectangle_MouseUp"/> 8 <Button Content="Button" Click="Button_Click"/> 9 </StackPanel> 10</Window>
C#
1 private void Button_Click(object sender, RoutedEventArgs e) { 2 //focusしたオブジェクトを取得したい。 3 //Rectangle rectangle = this.ActiveControl;//C# Formなら。 4//rectangle = FocusManager.GetFocusedElement as Rectangle;//動かない。 5 IInputElement focusedElement = FocusManager.GetFocusedElement(panel); 6 Rectangle rectangle = (Rectangle)focusedElement; 7 8 }
これって、Buttonを押した瞬間にrectangleのFocusはbuttonに移っているようです。
移る前のfocused objectを取得したいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。