Flat Button Style Problem
-
I'm trying to create a flat button style: Style
<Style x:Key="buttonStyle" TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Margin" Value="0"/> <Setter Property="Padding" Value="0"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Height" Value="25"/> <Setter Property="Width" Value="75"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" Margin="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding BorderThickness}"> <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextElement.Foreground="{TemplateBinding Foreground}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Hover.Foreground}" /> <Setter TargetName="border" Property="BorderThickness" Value="1" /> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Pressed.Foreground}" />
-
I'm trying to create a flat button style: Style
<Style x:Key="buttonStyle" TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Margin" Value="0"/> <Setter Property="Padding" Value="0"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Height" Value="25"/> <Setter Property="Width" Value="75"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" Margin="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding BorderThickness}"> <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextElement.Foreground="{TemplateBinding Foreground}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Hover.Foreground}" /> <Setter TargetName="border" Property="BorderThickness" Value="1" /> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="border" Property="BorderBrush" Value="{StaticResource Button.Pressed.Foreground}" />
Doesn't change from what to what? Is it "Red"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
Doesn't change from what to what? Is it "Red"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Sorry I wasn't clear. I set it to red but it shows as black.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Sorry I wasn't clear. I set it to red but it shows as black.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
You want "TextBlock" instead of TextElement, apparently: [https://stackoverflow.com/questions/249671/changing-the-foreground-colour-of-a-contentpresenter-in-a-listbox\](https://stackoverflow.com/questions/249671/changing-the-foreground-colour-of-a-contentpresenter-in-a-listbox)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
You want "TextBlock" instead of TextElement, apparently: [https://stackoverflow.com/questions/249671/changing-the-foreground-colour-of-a-contentpresenter-in-a-listbox\](https://stackoverflow.com/questions/249671/changing-the-foreground-colour-of-a-contentpresenter-in-a-listbox)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Nope, didn't work. I guess I could replace the ContentPresenter with a TextBlock, but then I'd need a DP behind it for the text. There's gotta be a XAML way to do this
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
Nope, didn't work. I guess I could replace the ContentPresenter with a TextBlock, but then I'd need a DP behind it for the text. There's gotta be a XAML way to do this
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
If content is a "string" (as in your case), the Button uses a TextBlock; if content is some UI element composite, a "ForeGround" color may make little sense. So, yes, I would have used a TextBlock (as "content") in the first place. (I sometimes use one or more FontIcons overlayed in a grid). (The "dynamic" resource binding also makes little sense in this case)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I