I am trying to define a global button style in App.xaml, and it mostly works as expected Has been doing. However, I can not understand how the foreground should be done in the right way. No matter what I have to do, I'm getting the default TextBlock style (which sets the color to white)
& Lt; Setter Property = "Override Default Style" value = "true" /> & Lt; Setter property = "focus visual style" value = "{static processing button focus visual}" /> & Lt; Setter property = "foreground" value = "red" /> & Lt; Setter property = "padding" value = "5" /> & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "Button" & gt; & Lt; Grid X: Name = "Grid Mainbooten" Render TransformAugin = "0.5, 0.5" & gt; & Lt; Grid.RenderTransform & gt; & Lt; ScaleTransform x: Name = "Scale transformform" center X = "0.5" center Y = "0.5" /> & Lt; /Grid.RenderTransform> & Lt; VisualStateManager.VisualStateGroups & gt; & Lt; VisualState Group x: Name = "General Location" & gt; & Lt; VisualState X: Name = "General" /> & Lt; VisualState X: Name = "mouseover" /> & Lt; VisualState X: Name = "Pressed" & gt; & Lt; Storyboard & gt; & Lt; DoubleAnimation Storyboard.TargetName = "scaleTransform" Storyboard.TargetProperty = "ScaleX" period = "0" to = "0.85" /> & Lt; / Storyboard & gt; & Lt; / VisualState & gt; & Lt; / VisualStateGroup & gt; & Lt; /VisualStateManager.VisualStateGroups> & Lt; Ellipse x: name = "oval" HorizontalAlignment = "muscles" VerticalAlignment = "muscle" StrokeThickness = "2" stroke = "{StaticResource standardBackground}" Fill = "{StaticResource standardBackground}" /> & Lt; Content Viewer Horizontal Element = "Center" Vertical Alignment = "Center" margin = "4, 8" /> & Lt; / Grid & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt; I think I could change ContentPresenter to a TextBlock, which would be fine for this particular application, but I'm looking for a more general solution.
Thank you, WTS
As Marcus Hütter said, the problem might be There is an underlying style for you that will define a TextBlock and when button content is set to a string, then TextBlock will be created, where your In the ContentPresenter template, this will raise the text block underlying style and this is the reason why you are having this problem. You can disable the built-in style for TextBlock s, which is the string by specifying the DataTemplate to string Is created for . Add the following for App.xaml ... Application ... & gt; & Lt; Application.Resources & gt; & Lt; DataTimeplate xmlns: sys = "clr-namespace: system; assembly = mscorlib" datatype = "{x: type sys: string}" & gt; & Lt; TextBlock Text = "{Binding}" & gt; & Lt; TextBlock.Resources & gt; & Lt; Style TargetType = "{x: type text block}" /> & Lt; /TextBlock.Resources> & Lt; / TextBlock & gt; & Lt; / DataTemplate & gt; & Lt ;! --...-- & gt; & Lt; /Application.Resources> & Lt; / Application & gt;
Comments
Post a Comment