When i added the style for Interaction.Behaviors in XAML, it have been error as below. Actually, i just want to add the common style and it will be using in each view.
So, should i add the more?
The property "Behaviors" does not have an accessible setter.
The property "Behaviors" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "Behaviors". For attached properties, the declaring type must provide static "GetBehaviors" and "SetBehaviors" methods.
i have error in this line.
<Setter Property="e:Interaction.Behaviors">
<Setter.Value>
here is my all sample source code.
<Window.Resources>
<Style x:Key="ToolTipTouchStyle" TargetType="{x:Type TextBlock}">
<!--<Setter Property="e:Interaction.Behaviors" Value="localToolTip:ToolTipTouchScreen" />-->
<Style.Setters>
<Setter Property="e:Interaction.Behaviors">
<Setter.Value>
<localToolTip:ToolTipTouchScreen />
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</Window.Resources>
public class ToolTipTouchScreen : Behavior<UIElement>
{
Timer timer { get; set; }
ToolTip toolTip { get; set; }
protected override void OnAttached()
{
base.OnAttached();
timer = new Timer();
timer.Interval = 5000;
timer.Elapsed += OnTimerElapsed;
AssociatedObject.MouseLeave += OnMouseLeave;
AssociatedObject.MouseLeftButtonUp += OnMouseLeftButtonUp;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.MouseLeave -= OnMouseLeave;
AssociatedObject.MouseLeftButtonUp -= OnMouseLeftButtonUp;
}
public void OnMouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
CloseToolTip();
}
public void OnMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (((dynamic)sender).ToolTip is string)
{
toolTip = new ToolTip();
toolTip.Content = ((dynamic)sender).ToolTip;
}
else
{
toolTip = (ToolTip)((dynamic)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);
}
}