Trying add a Trigger to a Style programmatically. I want the property for the Trigger Setter to be "Template". I also want the Setter Value to be a DynamicResource-
This is what my .xaml looks like, I want to add the trigger programmatically though:
<Style x:Key="ContentStyle" TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter
Property="Template"
Value="{DynamicResource HoverStyle1}" />
</Trigger>
</Style.Triggers>
</Style>
This is what I have so far in C#, which does not compile, namely the setter.Propery and setter.Value lines:
Style myStyle = null;
myStyle = listboxPatientList.TryFindResource("ContentStyle") as Style;
Setter setter = new Setter();
setter.Property = UIElement.Template;
setter.Value = {DynamicResource HoverPatientFull};
Trigger trigger = new Trigger();
trigger.Property = UIElement.IsMouseOverProperty;
trigger.Value = true;
trigger.Setters.Add(setter);
myStyle.Triggers.Add(trigger);
My reasoning for wanting to do this programmatically is because my system is having trouble specifying between mouseevents and touchevents. I've found a way programmatically to determine input device, depending on that situation this trigger should be added or not present. If the trigger is present when there is a touchevent, it does not register it as a mouseclick, just a mouseover.