DataGrid column headers, cant style properly - c#

I want to change the padding and colors of a DataGrid's column headers. The padding works fine but if I change the background color the cell grippers dissappear and there is no longer mouse over or mouse pressed affects on the cells. Here's what I am doing -
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Collection}" AlternatingRowBackground="#FFF7F7F7">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Padding" Value="20,10,20,10"/>
<Setter Property="Background" Value="#FFAACCFF"/>
</Style>
</DataGrid.ColumnHeaderStyle>
...
...
...
</DataGrid>
Anybody know how to change the background color properly? I would also like to change the colors of the mouse over and mouse pressed events. I think it has something to do with triggers, anyone know?
Edit: Here is a picture of what my DataGrid header looks like, as you can see no grippers and no mouseover color change (it doesnt show in the screenshot but my mouse is on top of Property2).

Something you might consider is changing the row color during the Row PrePainting or Row PostPainting event; it should give you better control on some of the smaller things you want to do and allow you to customize it based on the values in the grid/row.

I would suggest you to define your own ControlTemplate for DataGridColumnHeader. Inside that template define your own gripper and color.
As you mentioned you can use triggers to change color inside control template. Internet is full of examples which uses triggers to change color for example take a look at this post

Related

Avalonia how using easing for color transition

I want to make pretty background filling for my buttons. Color filling want started from center (like default Android animation for click). I reading official guide, but my code dont give that effect (only smoothing change color, without easing). Easing not working for me, only duration...
<Style Selector="Button">
<Setter Property="Transitions">
<Transitions>
<BrushTransition Property="Background" Duration="0:0:0.5" Easing="CircularEaseInOut"/>
</Transitions>
</Setter>
</Style>
Sorry for my pure explanation, this CSS animation looks like my wish.

WPF Custom Transparent Button

I would like create a button with text and image inside in, but this button should be transparent without loose behavior as cursors hand on mouse over and so on..
Also, it doesn't change its background color on mouse over. It's Always should appear transparent showing only my text and my image.
Is it possibile?
I think a very simple ControlTemplate will produce the desired output :
<ControlTemplate x:Key="TransparentButton" TargetType="Button">
<ContentPresenter Cursor={TemplateBinding Cursor}/>
</ControlTemplate>
Then simply apply if to the Templateproperty of your button.
Just add a {TemplateBinding Property} for the any properties you want to inherit. You should have a look at the default ControlTemplates on MSDN for your specific target (it may vary if targeting WP8, Silverlight or desktop)

Border around extension of 'Run' element

I'm creating a WPF application which shows a list of styled messages. My goal is to have the contents of multiple styled messages selectable, similar to how you can in Skype:
Currently, I have a ListBox which contains an extension of ListBoxItem that is styled to my needs:
However, this method does not satisfy my goal of being able to select the text of multiple messages at the same time. It is only possible to select the text inside one message.
I also tried to put my custom elements inside a RichTextBox control within BlockUIContainers (which is what I suspect I will end up having to use), but the text inside each element cannot be selected, only the entire element:
Next, I attempted to extend the "Run" element, but I cannot figure out how to put a border around it to style an individual message.
<Run.Style>
<Style TargetType="{x:Type Run}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Run}">
<Border Background="{TemplateBinding Background}" x:Name="Bd" CornerRadius="2">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Run.Style>
With this XAML, I tried to surround the content of the Run using a template, a border element, and a content presenter. However, the Run control does not appear to support templates.
If anybody could point me in the right direction, that would be greatly appreciated.
I don't know if this will help you but is just another idea...
Use one text control with transparent background so you can select all the text at once. Then you have to draw rectangles behind the text blocks. Like an optical ilussion.
The challenge here is calculating the exactly size of the text rectangle box and the text allignment. My idea is having a predefined sizes and positions design (left text box, right text box, date, etc) so the size and positioning calculations are easier.
Another idea is play with the mouse and/or selection events. During the user text selection replace it programatically with your own selection. The user will think that is he who is selecting the text but is the application who is doing it. Another illusion...
I hope you could resolve it.

Set the MenuItem BackGround color (The right way)

Whenever I try to change the background color to a menu adding the following code to the app.xml
<Style TargetType="MenuItem">
<Setter Property="Background" Value="#FF9B9B9B" />
</Style>
I get this lighter shade of gray around the menu, which color isn't set by the background property:
I know there are similar questions around, but the answers I've found haven't helped me.
That sort of thing is coded into the various ControlTemplates for MenuItems. You will probably have to create your own. (You could copy the defaults and edit them to your liking though)

WPF BubbleSeries, iterate over the bubbles and set the style

I have a BubbleSeries within a Chart. I bind data to the BubbleSeries and set a specific color to the bubbles.
What I want to do is to iterate over all the bubbles and set each bubble's color to specific color depending on the value.
My bubbles, two series:
The gray bubbles should always be gray, but the blue bubbles should have different colors depending on their SizeValue.
Any clues how to iterate over the bubbles and set their specific color? Possible?
I actually found a solution:
I didn't need to iterate over my bubbles, instead I solved the problem with a ValueConverter.
I have a ValueConverter that takes a value and return a color depending on that value.
I bind the response from my ValueConverter to my DataPointStyle:
<Charting:BubbleSeries.DataPointStyle>
<Style
TargetType="Charting:BubbleDataPoint">
<Setter
Property="Background">
<Setter.Value>
<SolidColorBrush
Color="{Binding Path=PropertyOnObjectBoundToGraph, Converter={StaticResource colorFormater}}"></SolidColorBrush>
</Setter.Value>
</Setter>

Categories

Resources