アプリケーション全体で有効にする方法はありToolTipService.ShowOnDisabled = trueますか、または WPF アプリケーションのすべてのコントロールに対して手動で設定する必要がありますか?
すべてのコントロールのスタイルを変更することが良い解決策だとは思いません。
のプロパティ メタデータをオーバーライドしToolTipService.ShowOnDisabledてデフォルト値を設定するtrue (by default value is false)と、アプリケーション内のすべてのコントロールに適用されます。
このコードをApp.xaml.cs
static App()
{
ToolTipService.ShowOnDisabledProperty.OverrideMetadata(typeof(Control),
new FrameworkPropertyMetadata(true));
}
VisualTreeHelperクラス ( msdn ) と静的メソッドToolTipService.SetShowOnDisabled( msdn )を使用できます。
すべての要素を反復処理し、ShowOnDisabledプロパティを に設定する単純なクラスを作成しましたTrue。
class ToolTipServiceHelper
{
public void EnumVisual(Visual myVisual)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
{
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
ToolTipService.SetShowOnDisabled(childVisual, true);
EnumVisual(childVisual);
}
}
}
使用例:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ToolTipServiceHelper ttsh = new ToolTipServiceHelper();
ttsh.EnumVisual(this.Content as Visual);
}
}