How to make DataGrid transparent? - c#

How to make DataGrid transparent?
I'm trying to use Background of DataGrid itself, but this doesn't seem to work.
UPD I need only background and borders transparent, not everything! Text should be visible.

So, my solution... use both Background="Transparent" and RowBackground="Transparent"

Have you tried setting the Opacity property to 0.0 ?
A value of 0.0 makes the element
completely transparent

<DataGrid
Background="Transparent" RowBackground="Transparent">
</DataGrid>

Try this:
Background="Transparent" RowBackground="Transparent"
and
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Background" Value="Transparent" />
</Style>
</DataGrid.RowHeaderStyle>

It's an undocumentd feature but if you set the visability to Hidden it's the same as setting the element to transparent.

I'm not sure which background you are trying to change, but you can set any background by overriding the DataGrid's ControlTemplate. Your best bet is probably to copy the default DataGrid ControlTemplate from here and then modify the necessary background to match your needs.

When you inicialize datagrid put this tag GridLinesVisibility with argument None
For example:
<DataGrid GridLinesVisibility="None"/>

Related

Wpf Custom ListBox with Rounded Border

I have extended ListBox control and wanted to give it rounded corner so I have applied styles as below and it works fine:
<control:MultiSelectionListBox SelectionMode="Extended" ItemsSource="{Binding Offerables,Mode=TwoWay}"
SelectedItemsList="{Binding SelectedOfferables, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name"
Grid.Row="6" Grid.Column="0" MaxHeight="150">
<control:MultiSelectionListBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
</control:MultiSelectionListBox.Resources>
</control:MultiSelectionListBox>
but I have too many Listboxes and I don't wanted to add style in each and every control individually.
I wanted to define this style in app.xaml and wanted to reuse that design by name like Style = "{StaticResource RoundedListBoxStyle}".
I have tried like below in app.xaml but with no luck
<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
<Setter Property="Border" Value="10"></Setter>
</Style>
The member Border is not recognized or is not accessible.
Please guide me what I am doing wrong here.
Finally I managed to do that as Bradley Uffner mentioned in the comment Border is not the property of the ListBox and we cannot use it in style like that. I used Style.Resource and mentioned Style for Border elements as below:
<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
</Style.Resources>
</Style>
and it worked. :)

How can I get a WPF TextBox to auto resize after a style change?

I have a standard TextBox with a fixed width of 150 and TextWrapping set to NoWrap, this makes the control behave just like the old WinForms version - which is what I want.
However, when I click a button, I want to effectively 'convert' the TextBox into a label. To save me messing around with multiple controls, I have decide this is best done by changing the style to look like a label. Most of this is working fine, except I want the new style to auto-resize the width of the Control to ensure all text is displayed without the need to drag a selection with the mouse.
In an attempt to do this I have set the Width to auto and then MinWidth to 150, something like this:
<Style x:Key="TypeConfusedTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Width" Value="Auto" />
<Setter Property="MinWidth" Value="150" />
<Setter Property="IsTabStop" Value="False"/>
</Style>
Which I then assign on button click like so:
textBox1.Style = (Style)FindResource("TypeConfusedTextBox");
The problem is that after the Style is changed, the control just remains as a fixed width of 150. If I apply the same Width and MinWidth values directly to the TextBox with the designer (or in the xaml) then is grows as expected when restyled, but so does the original style which I do not want to happen.
What am I missing here?
I'm only guessing that you're setting TextBox.Width somthing like <TextBox Width="150" .../> if that is the case then, according to Dependency Property Setting Precedence List Style won't override your fixed value. Try setting initial Width like this:
<TextBox>
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Width" Value="150" />
</Style>
</TextBox.Style>
</TextBox>
The answer by dkozl is exactly the reason why it wasn't working, and is the solution I intend to use.
However, after I posted this question I continued to try a few different things, one of which was to override the width values in code. So just to demonstrate an alternative, here is what I changed my button click code to look like:
textBox1.Style = (Style)FindResource("TypeConfusedTextBox");
textBox1.ClearProperty(WidthProperty);//this sets it to "Auto"
textBox1.MinWidth = 150;
Again, this is just an alternative, I am not recommending it as the best approach.

Removing all DataGrid row and cell borders

I want to hide (or remove) all the borders of all the rows (and subsequently cells) in my datagrid, think a basic HTML table. I've looked all over and most questions seem to be about styling them and not hiding them.
I've already tried setting the BorderBrush and BorderThickness like so:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Style>
</DataGrid.RowStyle>
Tried the same for the CellStyle, but no dice, still seeing borders.
What about setting GridLinesVisibility="None"?
<DataGrid GridLinesVisibility="None">
...
<DataGrid>
You could also do it this way
dataGrid.GridLinesVisibility = DataGridGridLinesVisibility.None;

How can DataGridComboBoxColumn style be changed?

I need to change border style to invisible on "DataGridComboBoxColumn"...
How can I do it? I hope there is another way then changing to datagridTemplate and put combobox element with my style inside....
You can try this solution:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a5777acb-ef85-40e3-b371-d803cbe26763/
I needed to add .EditingElementStyle
<wpfToolkit:DataGridComboBoxColumn x:Name="dgcSource" Header="Source"
SelectedValueBinding="{Binding ObjectItemSourceId, TargetNullValue=0}"
SelectedValuePath="ID"
DisplayMemberPath="Name"
SortMemberPath="SourceName">
<wpfToolkit:DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="BorderBrush" Value="Transparent"/>
</Style>
</wpfToolkit:DataGridComboBoxColumn.EditingElementStyle>
</wpfToolkit:DataGridComboBoxColumn>

disable wpftoolkit chart datapoint

Does anybody know how to turn off the datapoints for a noraml LineSeries in a WPFToolkit chart? I find them to be very annoying, and not useful to my purposes, but I can't find a simple property or anything like that on the class itself.
You want to hide them?
It is possible if to set the empty ControlTemplate to the Template property.
Here is the example:
<Window.Resources>
<Style x:Key="InvisibleDataPoint" TargetType="{x:Type charting:DataPoint}">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Template" Value="{x:Null}"/>
</Style>
</Window.Resources>
<Grid>
<charting:Chart>
<charting:LineSeries ItemsSource="{Binding ChartItems}" IndependentValuePath="XValue" DependentValuePath="YValue"
DataPointStyle="{StaticResource InvisibleDataPoint}"/>
</charting:Chart>
</Grid>
And although the points are invisible, you can set other properties, like Background and change the look of chart.

Categories