C
C#•3w ago
malkav

WPF Styling of a button

I have this button Style in WPF that I am trying to make https://pastebin.com/xCTrerLg The problem with this at the moment being that the following states: Hover, Pressed, and Disabled are not changing their colors appropriately. When I use the Warning class for example, I seem to get the Primary colors on those states, but the Warning color on the base button. When I use Secondary it changes everything to just the Secondary color, and not the state colors I defined at the top of the file. etc, etc. So now I come here for help, in the hopes of seeing what I did wrong 😅 Additional resources: ButtonHelper class: https://pastebin.com/9DZ09La9 How I implement the button in the pages:
<Page x:Class="CrystalTrack.Gui.Pages.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CrystalTrack.Gui.Pages"
xmlns:controls="clr-namespace:CrystalTrack.Gui.Controls"
mc:Ignorable="d">
<!-- ... -->
<Button Grid.Column="2" Grid.Row="0"
Style="{StaticResource InformButton}"
controls:ButtonHelper.ColorClass="Warning"
Click="ApiKeyButton_OnClick">
Text here
</Button>
<!-- ... -->
<Page x:Class="CrystalTrack.Gui.Pages.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CrystalTrack.Gui.Pages"
xmlns:controls="clr-namespace:CrystalTrack.Gui.Controls"
mc:Ignorable="d">
<!-- ... -->
<Button Grid.Column="2" Grid.Row="0"
Style="{StaticResource InformButton}"
controls:ButtonHelper.ColorClass="Warning"
Click="ApiKeyButton_OnClick">
Text here
</Button>
<!-- ... -->
2 Replies
malkav
malkav•3w ago
Update to the Button Stylesheet: https://pastebin.com/YXPy0kXS
leowest
leowest•3w ago
do you have some binding to tell which status it should be in? or u want to create the button based on the colorclass if so u will have to provide how you're doing your converter and DPs My understanding is that u would need a multidatatrigger for the IsMouseOver/IsPressed(without looking at what your DP or converters do)
<MultiDataTrigger>

<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsEnabled}" Value="True" />
<Condition Binding="{Binding IsMouseOver}" Value="True" />
<Condition Binding="{Binding Path=(local:ButtonHelper.ColorClass), RelativeSource={RelativeSource Self}}"
Value="Warning" />
</MultiDataTrigger.Conditions>

<Setter TargetName="border" Property="Background" Value="{DynamicResource color u want}" />
<... any other setter />

</MultiDataTrigger>
<MultiDataTrigger>

<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsEnabled}" Value="True" />
<Condition Binding="{Binding IsMouseOver}" Value="True" />
<Condition Binding="{Binding Path=(local:ButtonHelper.ColorClass), RelativeSource={RelativeSource Self}}"
Value="Warning" />
</MultiDataTrigger.Conditions>

<Setter TargetName="border" Property="Background" Value="{DynamicResource color u want}" />
<... any other setter />

</MultiDataTrigger>
Want results from more Discord servers?
Add your server
More Posts
Converting from DTO to DomainModelHello, I'm developing the CRM for repairing the office equipment There are 7 stages of each ticket, cancellation token to stop Console.ReadLine is only working on the first tryI have the following method I got from stackoverflow ```cs async Task<string?> ReadLineAsync(Cancelllearning moq frameworkI'm trying to get my head around the moq framework but i can't seem to understand. Anyone got some g✅ .net best practices & useful patternsHi all, Looking for relevant material on the subject. Would appreciate your help. - main subjects mapping a dynamic object to an existing object and only map properties that exist in the source objI need help with patching an object in ASP Core, on my api i only send a partial data of the object when I want to enter to open my path, the click event is activatedthis is the code https://paste.ofcode.org/t3AqXpwPMuULScQt7vNkXF I do not know what to do✅ updated to Swashbuckle 6.6 from 6.4 and now my code doesn't compileI have this example from a book I'm reading about asp.net, it was working fine until I updated Swash✅ i feel like there is a really easy fix that i am missingwhy is this returning 0?✅ I might be stupid, but my score system adds two every time a collision happens instead of one.I can't figure out why. Then again, I don't know what I'm doing. I'm following a tutorial and this iplease help me understand this warninghttps://www.reddit.com/r/dotnet/s/5CSCmAlroV I have already posted the question on dotnet subreddit