Style in HeaderColumn in Datagrid - silverlight

Please see this following image of my datagird.
Now want a border in headerColumn. I have tried columnheader style but it did not work for me.
I want following style of header of datagrid.Please see the following image.
How can i achieve this style in datagird.
Thanks

You have to change the DataGrid template, not columnheader. In the default DataGrid template there is:
<sdk:DataGridColumnHeadersPresenter x:Name="ColumnHeadersPresenter" Grid.Column="1"/>
I think you have to edit over there.

Related

WPF - Not working IsReadOnly in DataGrid with custom CheckBox style

I currently have a custom CheckBox style which I use in a DataGrid. However, when I specify the IsReadOnly="true" property in a DataGridCheckBoxColumn, this is no longer working (can I still click and change the value of the CheckBox). I also used Expression Blend to extract a copy of the original WPF style, and this one has the same problem. Only the original CheckBox style seems to be working, which I don't want.
I currently manage to solve it by creating a new style based on my normal one with the IsHitTestVisible and Focusable properties on false, but I want the IsReadOnly property from the DataGridCheckBoxColumn to work without this workaround.
How can I achieve this result?
May be it is your case: try to set somewhere in the style this xaml:
IsReadOnly="{TemplateBinding}"
or
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
Hope this help.
There is an "IsEnabled" on CheckBox (should be on all other controls, I think) can do the job.

How to make WPF DataGrid VerticalScrollBar Always Visible?

Do you knows how to make the WPF DataGrid VerticalScrollBar always visible, even if there is no data to display without putting DataGrid object instid a ScrollViewer?
You should be able to set the ScrollViewer.VerticalScrollBarVisibility attached property like so:
<DataGrid ScrollViewer.VerticalScrollBarVisibility="Visible" ...

Make a silverlight textblock act like a hyperlink

I'm pretty new to silverlight. I have a text block that is displayed inside a datagrid
(inside a DataGridTemplateColumn.CellTemplate template to be precise).
I'd like to dynamically make some of the textblocks into hyperlinks that open a new window.
Is there a way to do this - so far all I can come up with is using a hyperlink button and trying to style it to look like a text block.
Any help would be very much appreciated.
HyperlinkButton is a ContentControl so it can actually take some kind of pre-styled TextBlock (or other control) as it's content (instead of just using a simple string as Content).
<HyperlinkButton NavigateUri="http://myurl.com">
<TextBlock Text="My Link Text" Foreground="Black" />
</HyperlinkButton>
You would have to use a custom HyperlinkButton template if you wanted to style it to get rid of the default teal colored focus ring, etc. You could also set the IsEnabled property of the HyperlinkButton to false to prevent link behavior on any cells that weren't actually links if you are trying to set them up in some dynamic way.

WPF resizing TextBlock

I have a textblock in a grid in WPF.
I want the text to dynamically size (font) when resized. At the moment textboxes, comboboxes do this, but the the textblock stays the same. Is it possible?
Instead of trying to manually rig a TextBlock to do this, just edit the default template of a TextBox and remove the border and background, then in the style make it set the IsReadOnly flag. This way you get the textblock sizing, as well as copy-paste for free.
You can use a ViewBox for this.
eg:
<Viewbox Stretch="Uniform">
<TextBlock Text="Test" />
</Viewbox>
use expression blend for getting the default template of TextBox, then you can edit it as you required.

How to hide the Column header in a WPF DataGrid?

I am using a DataGrid in Expression Blend but I just need to show only the registries and hide the ColumnHeader.
How do I do that?
In the DataGrid there is a Header section where the field Header Visibility could be set to None.
Or in xaml for the Datagrid add the property
HeadersVisibility="None"
Both DataGrid of namespace System.Windows.Controls and
WpfToolkit:DataGrid of Microsoft.Windows.Controls have the property
HeadersVisibility="None"
In the properties window of DataGrid you can indeed choose from the available options
None
Column
Row
All
But this doesn't appear in the Properties window of WpfToolkit:DataGrid
So as far as I know, you need to type that in inside your .xaml file.
<WpfToolkit:DataGrid HeadersVisibility="None">
...
</WpfToolkit:DataGrid>
If you want I can post the whole UserControl. Is that useful ?
This may be double posted, SO is being weird, but you can do this from code behind too.
C# code behind with a XAML datagrid named dg_Main would be:
dg_Main.HeadersVisibility = Microsoft.Windows.Controls.DataGridHeadersVisibility.None;
Doing this in code behind makes it easy to dynamically show and hide headers as needed.

Resources