wpf - Setter in property trigger fails if target property already has an explicit value -


I currently try to create a ControlTemplate for button I'm replacing the class in WPF, instead of the normal view tree which looks like a small (X) close icon on the tab of Google Chrome. I decided to use the path object in XAML to achieve the effect, setting the red background of the icon icon, using the property trigger, IsMouseOver responds to the change in property.

Here's a XAML test app:

  & lt; Window X: orbit = "widget.index1" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006 / Xaml "title =" window 1 "height =" 300 "width =" 300 "& gt; & Lt; Window.Resources & gt; & Lt; Style x: key = "border style" target type = "border" & gt; & Lt; Style.Triggers & gt; & Lt; Trigger Property = "Ismouth Over" Value = "True" & gt; & Lt; Setter Property = "Background" & gt; & Lt; Setter.Value & gt; & Lt; Solid color brush color = "# cc 0000" /> & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Catalyst & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; ControlMattlet X: key = "closebuttonplate" target type = "button" & gt; & Lt; Border width = "12" height = "12" corner Radius = "6" borderbrows = "# aaaaaai" background = "transparent" style = "{static resource border style}" tooltip = "close" & gt; & Lt; Viewbox margin = "2.75" & gt; & Lt; Path Data = "M 0,0 L10,10 M0,10L10,0" stroke = "{Binding Borderbrush, Relative Soros = {Reserved Soros FindAncestor, Esterroier Type = Border, Eistent Level = 1}} StrokeTrains = 1.8 "/> & Lt; / Viewbox & gt; & Lt; / Border & gt; & Lt; / ControlTemplate & gt; & Lt; /Window.Resources> & Lt; Grid Background = "White" & gt; & Lt; Button template = "{static resource closet template}" /> & Lt; / Grid & gt; & Lt; / Window & gt;  

Note that the circular background is always there - it's just transparent when the mouse is not on it.

With this problem, there is no change in the presence of the trigger, but only the presence of the button working in the INS. However, if I remove the Background = "Transparent" value in Border in the object in the ControlTemplate , triggers work (albeit only on 'X')

I can not really explain this. The setters recover for any other properties fixed in the borderStyle resource task, but the Background setter fails, such as the default background ControlTemplate .

Why is any thoughts happening and how can I fix it? I know that I can easily replace this code with this code, for example, one. PNG-based image, but I want to understand why the current implementation is not working.

Thank you! :)

Try moving the "Background" assignment to the Style from inside the border declaration:

  & lt; Style x: key = "border style" targetType = "border" & gt; & Lt; Setter property = "background" value = "transparent" /> & Lt; Style.Triggers & gt; & Lt; Trigger Property = "Ismouth Over" Value = "True" & gt; & Lt; Setter Property = "Background" & gt; & Lt; Setter.Value & gt; & Lt; Solid color brush color = "# cc 0000" /> & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Catalyst & gt; & Lt; /Style.Triggers> ... & lt; Border width = "12" height = "12" corner Radius = "6" borderbrush = "# aaaaaa" style = "{borderline of static resources}" tooltip = "close" & gt;  

Styles can not override property which is clearly set. You have to set the value in style.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -