There is a radiobutton with a custom style, in which there is a rectangle defined through the XAML style named rectangle . I want to make it so that when you hover the mouse on the radiobutton , the rectangle smoothly changes its color, but only if the radiobutton not selected ( IsChecked = False ). I use code
<ControlTemplate.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="rectangle" Duration="0:0:0:0.5" Storyboard.TargetProperty="(Fill).(Color)" To="#5d4037"> </ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> Perhaps, I should make check through the code (C #)? If so, how to do it?
I tried to do it through code
ColorAnimation aRadioEnter = new ColorAnimation(); Color color1 = (Color)ColorConverter.ConvertFromString("##5d4037"); aRadioEnter.Duration = new Duration(TimeSpan.FromSeconds(1)); aRadioEnter.To = color1; // Storyboard Storyboard; Storyboard = new Storyboard(); Storyboard.Children.Add(aRadioEnter); Storyboard.SetTargetName(aRadioEnter, target.Name); but I don’t know how to specify a target (rectangle Rectangle ) via Storyboard.SetTargetProperty .
And in general, how to get access to the controls through the code? For example, if I need to change the fill color of the Rectangle .
RadioButton? What do you want to achieve? - VladD