WPFにおいてToolTipの表示を自由に変更したいと思っています。
以下のサイトを参考にしました。
https://codeday.me/jp/qa/20190402/512196.html
コードなどは一番下の詳細の欄で参照してください。
実際に作成してみると
System.Windows.Markup.XamlParseException HResult=0x80131501 Message=''System.Windows.StaticResourceExtension' の値の指定時に例外がスローされました。' 行番号 '16'、行位置 '26'。 Source=PresentationFramework スタック トレース: 場所 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 内部例外 1: Exception: 'CenterToolTipConverter' という名前のリソースが見つかりません。リソース名は大文字と小文字を区別します。
下の画像にあるとおり、CenterTooltipConverterはmainwindow.xamlと同じ階層にあります。
なぜ参照されていないのかがわかりません。回答お願いします。
##環境
windows10 64 bit
visualstudio2017
##詳細
ディレクトリの構造は下の画像の通りです。
MainWindow.xaml:
MainWindowxaml
1<!-- Mainwindow.xaml MainWindow.xaml.csは特に実装はありません --> 2<Window x:Class="CTC_p1.MainWindow" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 6 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 7 xmlns:local="clr-namespace:CTC_p1" 8 mc:Ignorable="d" 9 Title="MainWindow" Height="450" Width="800"> 10 11 <StackPanel> 12 <Button Content="Test"> 13 <Button.ToolTip> 14 <ToolTip Content="ToolTip Text" 15 Placement="Bottom"> 16 <ToolTip.HorizontalOffset> 17 <MultiBinding Converter="{StaticResource CenterToolTipConverter}"> 18 <Binding RelativeSource="{RelativeSource Self}" Path="PlacementTarget.ActualWidth"/> 19 <Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth"/> 20 </MultiBinding> 21 </ToolTip.HorizontalOffset> 22 </ToolTip> 23 </Button.ToolTip> 24 </Button> 25 26 </StackPanel> 27</Window> 28 29
CeterToolTipConverter.csは以下の通りです。
//CenterToolTipConverter.cs using System.Threading.Tasks; using System.Windows; using System.Windows.Data; namespace notifyicon_p1 { public class CenterToolTipConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.FirstOrDefault(v => v == DependencyProperty.UnsetValue) != null) { return double.NaN; } double placementTargetWidth = (double)values[0]; double toolTipWidth = (double)values[1]; return (placementTargetWidth / 2.0) - (toolTipWidth / 2.0); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/19 09:24