Created
February 26, 2014 01:57
-
-
Save podhmo/9221917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application x:Class="FocusSample.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
StartupUri="MainWindow.xaml"> | |
<Application.Resources> | |
</Application.Resources> | |
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using System.Windows; | |
namespace FocusSample | |
{ | |
/// <summary> | |
/// App.xaml の相互作用ロジック | |
/// </summary> | |
public partial class App : Application | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="FocusSample.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:c="clr-namespace:FocusSample" | |
Title="MainWindow" Height="350" Width="525"> | |
<Window.Resources> | |
<Style TargetType="TextBox"> | |
<Setter Property="Height" Value="50"/> | |
<Setter Property="FontSize" Value="40"/> | |
</Style> | |
</Window.Resources> | |
<StackPanel> | |
<TextBox x:Name="Input"></TextBox> | |
<Button Height="50" x:Name="Button"> | |
<Button.Style> | |
<Style TargetType="Button"> | |
<Style.Triggers> | |
<DataTrigger Binding="{Binding ElementName=Button, Path=IsMouseOver}" Value="True"> | |
<Setter Property="FocusManager.FocusedElement" | |
Value="{Binding ElementName=Input}"/> | |
<Setter Property="Width" Value="100"/> | |
</DataTrigger> | |
</Style.Triggers> | |
</Style> | |
</Button.Style> | |
toplevelのtextboxへfocus | |
</Button> | |
<TextBox x:Name="DummyInput" Text="Dummy"></TextBox> | |
<c:WrappedTextBox x:Name="WrappedInput"/> | |
<Button Height="50" x:Name="Button2"> | |
UserControlのtextboxへfocus | |
<Button.Style> | |
<Style TargetType="Button"> | |
<Style.Triggers> | |
<DataTrigger Binding="{Binding ElementName=Button2, Path=IsMouseOver}" Value="True"> | |
<Setter Property="FocusManager.FocusedElement" | |
Value="{Binding ElementName=WrappedInput}"/> | |
<Setter Property="Width" Value="100"/> | |
</DataTrigger> | |
</Style.Triggers> | |
</Style> | |
</Button.Style> | |
</Button> | |
</StackPanel> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace FocusSample | |
{ | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="FocusSample.WrappedTextBox" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
mc:Ignorable="d" | |
FocusManager.IsFocusScope="True" | |
GotFocus="Container_GotFocus" | |
x:Name="Container" | |
d:DesignHeight="300" d:DesignWidth="300"> | |
<Grid> | |
<Grid.RowDefinitions> | |
<RowDefinition/> | |
</Grid.RowDefinitions> | |
<TextBox Grid.Row="0" x:Name="A" Background="AliceBlue"></TextBox> | |
</Grid> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace FocusSample | |
{ | |
/// <summary> | |
/// WrappedTextBox.xaml の相互作用ロジック | |
/// </summary> | |
public partial class WrappedTextBox : UserControl | |
{ | |
public WrappedTextBox() | |
{ | |
InitializeComponent(); | |
} | |
private void Container_GotFocus(object sender, RoutedEventArgs e) | |
{ | |
var input = this.A; | |
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(sender as DependencyObject), input); | |
e.Handled = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment