WPFで画面を作成していた時にFrameを使用していたのですが、起動時や画面遷移した時に枠線が出ていて見た目が悪すぎたので直しました。
画面構成
StackPanel内にFrameを使用するようなXAMLです。
画面の状態によって表示を切り替えるためにFrameを使用していましたが、サンプルなので空のパネルにFrame乗っけているだけです。
<Window x:Class="FocusTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:FocusTest" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <StackPanel> <Frame Height="100" Background="OldLace"> </Frame> </StackPanel> </Window>
画像がこちらです。クリーム色の部分がFrameです。タブでフォーカス当てるとこのように枠線が出てきてしまいます。
ボタンとかなら許せたのですが背景にまでフォーカス当たるのは微妙な感じです。

枠線を消す方法
枠線を消すにはApp.xamlを編集します。ここで以下のように設定すると全体的に適用されます。
TargetTypeをButton等に変更するとボタンのフォーカスも消すことができます。
<Application x:Class="FocusTest.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:FocusTest" StartupUri="MainWindow.xaml"> <Application.Resources> <Style TargetType="Frame"> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> </Style> </Application.Resources> </Application>
以上です。
コメント