0
タッチスクリーンでツールチップの新しい共通クラスが作成されました。そして、私はツールチップのコントロールとページをたくさん持っています。だから私はXAMLでこの共通のクラスについて使いたいだけです。XAMLで共通クラスをバインドする方法
public class CommonLayout : Window
{
Timer Timer { get; set; }
ToolTip toolTip { get; set; }
public CommonLayout(TextBlock control)
{
Timer = new Timer();
Timer.Interval = 3000;
Timer.Elapsed += OnTimerElapsed;
control.MouseLeave += OnMouseLeave;
control.MouseLeftButtonUp += OnMouseLeftButtonUp;
}
public void OnMouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
CloseToolTip();
}
public void OnMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
toolTip = ((ToolTip)((TextBlock)sender).ToolTip);
toolTip.IsOpen = true;
Timer.Start();
}
private void CloseToolTip()
{
if (toolTip != null)
{
toolTip.IsOpen = false;
}
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
Timer.Stop();
Application.Current.Dispatcher.BeginInvoke((Action)CloseToolTip, DispatcherPriority.Send);
}
}
共通クラス@ @XAML 私はのTextBlockの3種類以下についての一般的なツールヒントクラスのバインドにしたいです。 他のページでも使用する必要があります。
<StackPanel Margin="30">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="ToolTip Test"
ToolTipService.ShowOnDisabled="True" >
<TextBlock.ToolTip>
<ToolTip Placement="Mouse" Content="This is ToolTip Test." />
</TextBlock.ToolTip>
</TextBlock>
<TextBlock x:Name="textBlock1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="ToolTip Test1"
ToolTipService.ShowOnDisabled="True" >
<TextBlock.ToolTip>
<ToolTip Placement="Mouse" Content="This is ToolTip Test." />
</TextBlock.ToolTip>
</TextBlock>
<TextBlock x:Name="textBlock2" HorizontalAlignment="Left" TextWrapping="Wrap" Text="ToolTip Test2"
ToolTipService.ShowOnDisabled="True" >
<TextBlock.ToolTip>
<ToolTip Placement="Mouse" Content="This is ToolTip Test." />
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
私は私の答えに追加しました。もう少し考えがありますか? – Song
私は、現在のコメントが規則を破らないとは確信していません。しかし、私の答えが本当に助けになったら、ここに記入してください。 –