Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thank you for your help, but I'm somewhat new to WPF, and am not very good with RoutedEvents. I added the first section of code like you suggested, but when I run it I get the following error:</p> <p><strong>Cannot convert string 'MouseRightButtonUp' in attribute 'RoutedEvent' to object of type 'System.Windows.RoutedEvent'. RoutedEventConverter cannot convert from System.String. Error at object 'System.Windows.EventTrigger' in markup file 'MyProgram;component/frmmain.xaml' Line 62 Position 43.</strong></p> <p>My XAML style code now looks like this:</p> <pre><code> &lt;Style TargetType="{x:Type Label}" x:Key="NavLink"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Label}"&gt; &lt;Border x:Name="NavLinkBorder" Background="#CCCCCC"&gt; &lt;ContentPresenter x:Name="NavLinkContent" Margin="4,4,4,4" /&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter TargetName="NavLinkBorder" Property="Background" Value="#CCCCCC" /&gt; &lt;Setter Property="Cursor" Value="Hand" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsMouseOver" Value="False"&gt; &lt;Setter TargetName="NavLinkBorder" Property="Background" Value="#EAEAEA" /&gt; &lt;/Trigger&gt; &lt;EventTrigger RoutedEvent="MouseRightButtonUp"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;ColorAnimation To="#FF0000" Duration="0" Storyboard.TargetName="NavLinkBorder" Storyboard.TargetProperty="(Background).(Color)" /&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>And, I didn't post this before, but this is what the code looks like that generates my labels:</p> <pre><code> Label tempLabel = new Label(); tempLabel.Content = "My Link"; tempLabel.ContextMenu = (ContextMenu)FindResource("NavContextMenu"); tempLabel.FontSize = 12; tempLabel.Foreground = new SolidColorBrush(appFunctions.HexToColor("#000057")); tempLabel.Name = "myNavLink"; tempLabel.Style = (Style)FindResource("NavLink"); tempLabel.MouseLeftButtonUp += new MouseButtonEventHandler(NavLink_LeftClicked); tempLabel.MouseRightButtonUp += new MouseButtonEventHandler(NavLink_RightClicked); navPanel.Children.Add(tempLabel); </code></pre> <p>When I get the error, it highlights this line from the above code:</p> <pre><code> tempLabel.Style = (Style)FindResource("NavLink"); </code></pre> <p>Maybe I'm not attaching the label's style correctly...?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload