I want to set the foreground (text) color to all my elements, you'll think it will be easy, but it is not. ..
& lt; Window foreground = "red" & gt; & Lt; Label content = "test" /> & Lt; Label content = "test" /> & Lt; Checkbox content = "checkbox" /> & Lt; / Window & gt; It has no effect ... I think this is the only way to work if I'm specifically setting the foreground property on each element
Maybe you know in a way?
The reason for this is that the label and checkboxes Overrides in the form of the foreground property in their styles. Below is an ordinary rational tree of an example element that shows how the specified value travels below the tree at the window level: Window (red [local]) - & gt; Grid (Red [Inherited]) - & gt; Listbox (Red [Inherited]) - & gt; Listoboxime (Red [Inherited]) - & gt; StackPanel (Red [Inherited]) - & gt; Label (black [style]) - & gt; TextBlock (Black [Inherited]) - & gt; Textball (Red [Inherited]) The source of the value is displayed in the cell of the class. As you can see the legacy, the foreground property is set to its default style on label automatically < Pre> & lt; Style x: key = "{x: type label}" TargetType = "{x: type label}" & gt; & Lt; Setter Property = "Foreground" value = "{DynamicResource {x: Static System Callers.ControlTextBruce}}" /> ... & lt; / Style & gt; As an alternative solution for this, we can use the following tricks. Define the default style for app controls (such as Label ) in the application (in App.xaml or windows inself). And in that default style, the foreground overrides the property to force the relative source to the nearest ancestor of control, which is still the desired value: Gt; Style TargetType = "{X: Type Label}" & gt; & Lt; Setter Property = "Foreground" value = "{Compulsive Relative Soros = {Relative Escher Ancestor Type = {x: Type Framework Element}}, path = (TextAlex.Eferg)}" /> & Lt; / Style & gt; & Lt; Style TargetType = "{x: type checkbox}" & gt; & Lt; Setter Property = "Foreground" value = "{Compulsive Relative Soros = {Relative Escher Ancestor Type = {x: Type Framework Element}}, path = (TextAlex.Eferg)}" /> & Lt; / Style & gt; After this our tree will look like this:
Window (red [local]) - & gt; Grid (Red [Inherited]) - & gt; Listbox (Red [Inherited]) - & gt; Listoboxime (Red [Inherited]) - & gt; StackPanel (Red [Inherited]) - & gt; Label (Red [binding from Stack Panel. (TextAlement.Efergen)]) - & gt; TextBlock (Red [Inherited]) - & gt; As you can see, restores our binding inheritance.
Such style is required to define for each element that foreground property in its genre @ dune suggested that not to be compulsive in every genre The ability to use BasedOn can be: & lt; Style x: key = "foreground inheritancefixstyle" target type = "control" & gt; & Lt; Setter Property = "Foreground" value = "{Compulsive Relative Soros = {Relative Escher Ancestor Type = {x: Type Framework Element}}, path = (TextAlex.Eferg)}" /> & Lt; / Style & gt; & Lt; Style TargetType = "{x: type label}" basson = "{static rsosor foreground inheritance fixtile}" & gt; & Lt; / Style & gt; & Lt; Style target type = "{x: type checkbox}" based on = "{static rsosor foreground inheritance fixtile}" & gt; & Lt; / Style & gt; Hope it helps.
Comments
Post a Comment