Xceed themes override all other styles - wpf

I'm using an xceed datagrid with the Office2007BlackTheme. I also have a lot of styles, that I want to apply to UI controls inside my datagrid. Unfortunately the theme seems to override everything as long as its inside the datagrid.
It is worth noting that datagrid-related styles like "ColumnManagerCell" or "DataRow" still work as expected.
For example: I want to use my own style for the scrollbars, but even though the style is set to be applied globally; <Style TargetType="{x:Type ScrollBar}">, it is still overridden in the datagrid. Outside of the grid it is not.
I realize that this is because, by default, the theme is set implicitly, but there doesn't seem to be anyway of setting it explicitly.
Is there a way to explicitly set the ScrollBar style (& others) after applying the theme? Maybe there's a way to base the tableflowview on the theme so it doesn't override other styles? I've looked around and did not find any solution.
I'm using Xceed DataGrid for WPF 6.3 with ThemePack 1-5. (Only DataGrid: xceed.com/xceed-datagrid-for-wpf paid version)
Any help is appreciated.
Here's my code for the DataGrid:
<xcdg:DataGridControl x:Name="datagrid"
ItemsSource="{Binding Source={StaticResource Features}}"
KeyUp="DatagridKeyUp"
AllowDetailToggle="True"
Margin="10"
NavigationBehavior="RowOrCell"
CellEditorDisplayConditions="RowIsBeingEdited,
MouseOverCell, MouseOverRow, RowIsCurrent, CellIsCurrent"
EditTriggers="BeginEditCommand, ClickOnCurrentCell,
SingleClick, CellIsCurrent, ActivationGesture, RowIsCurrent"
ItemScrollingBehavior="Immediate"
AutoCreateColumns="False">
<xcdg:DataGridControl.View>
<xcdg:TableflowView>
<!--Remove ugly header-->
<xcdg:TableflowView.FixedHeaders>
<DataTemplate>
<xcdg:ColumnManagerRow />
</DataTemplate>
</xcdg:TableflowView.FixedHeaders>
<!-- THEME IS SET HERE! -->
<xcdg:TableflowView.Theme>
<xcdg:Office2007BlackTheme/>
</xcdg:TableflowView.Theme>
</xcdg:TableflowView>
</xcdg:DataGridControl.View>
<xcdg:DataGridControl.Resources>
<Style TargetType="xcdg:TableViewScrollViewer">
<Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
</Style>
</xcdg:DataGridControl.Resources>
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="FeatureID" Title="FeatureID" ReadOnly="True"/>
<xcdg:Column FieldName="Name" Title="Feature name" ReadOnly="True" />
<xcdg:Column FieldName="Description" Title="Description" ReadOnly="True" />
<xcdg:UnboundColumn FieldName=" " />
</xcdg:DataGridControl.Columns>
<xcdg:DataGridControl.DetailConfigurations>
<xcdg:DetailConfiguration RelationName="Settings" UseDefaultHeadersFooters="False">
<xcdg:DetailConfiguration.Headers>
<DataTemplate>
<xcdg:ColumnManagerRow />
</DataTemplate>
</xcdg:DetailConfiguration.Headers>
<xcdg:DetailConfiguration.Columns>
<xcdg:Column FieldName="Name" Title="Name" ReadOnly="True" />
<xcdg:Column FieldName="Description" Title="Description" ReadOnly="True" />
<xcdg:Column FieldName="EditValues" Title="Edit Values" ReadOnly="True" />
<xcdg:Column FieldName="EditValueVar" Title="Edit Value" Width="150" ReadOnly="False"
CellContentTemplateSelector="{StaticResource SettingsDataTemplateSelector}"
DisplayMemberBinding="{Binding}" />
<xcdg:UnboundColumn FieldName=" " />
</xcdg:DetailConfiguration.Columns>
</xcdg:DetailConfiguration>
</xcdg:DataGridControl.DetailConfigurations>
</xcdg:DataGridControl>

Related

Telerik WPF GridView prevent focus on button click

I have a radgridview where one column is an edit button which redirects the page and the rest of the columns are databound from my source.
My problem is that to be able to press the edit button on a specific row for the first time the user basically has to press it twice because the first click for some reason focuses the entire gridview first into view.
This only happens when the entire gridview does not fit into the view so I am guessing it tries to automatically fit itself as best as it can before it lets me press the edit button - it does not happen if i press on any of the static uneditable fields - only on the edit button
<telerik:RadGridView Name="radGridView" VerticalAlignment="Top"
AutoGenerateColumns="False"
ValidatesOnDataErrors="None" IsReadOnly="True"
ShowColumnSortIndexes="True"
CanUserFreezeColumns="False"
ItemsSource="{Binding PagedSource, ElementName=radDataPager}" >
<telerik:RadGridView.Columns>
<telerik:GridViewColumn Header="Edit">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Edit" Style="{StaticResource HyperLinkButtonStyle}"
Click="EditButton_Click" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Organization}" Header="Organization"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding VisitDate, StringFormat=d}" Header="Visit Date"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Location}" Header="Location"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Address}" Header="Address"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonName}" Header="Contact Name"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonEmail}" Header="Contact E-mail"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactMobileNumberConcatenate}" Header="Contact Mobile Number"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactHomeNumberConcatenate}" Header="Contact Home Number"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactOfficeNumberConcatenate}" Header="Contact Office Number"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactFaxNumberConcatenate}" Header="Contact Fax Number"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Is there a way to prevent this focus from happening when I press on an edit button inside the grid? or am I missing something else
For some reason the problem was that I was using a button in the datatemplate as
<Button Content="Edit" Style="{StaticResource HyperLinkButtonStyle}" Click="EditButton_Click" />
Something about the Button was making the gridview have to first focus itself into the view before a subsequent click on that button would fire the click event in the cases where it was not fully fitting on the screen..
I ended up doing the workaround of simply using a telerik label and giving it a MouseLeftButtonDown event
<telerik:Label Content="Edit" TouchDown="EditButton_Click" MouseLeftButtonDown="EditButton_Click" Style="{StaticResource HyperLinkStyle}"/>
Pretty sure you should be able to use a regular label as well
The HyperLinkStyle is just a style that makes the label underlined and gives it a color and hover state
<UserControl.Resources>
<Style x:Key='HyperLinkStyle' TargetType='telerik:Label'>
<Setter Property='Template'>
<Setter.Value>
<ControlTemplate TargetType='telerik:Label'>
<TextBlock TextDecorations='Underline'>
<ContentPresenter TextBlock.FontFamily='Segoe UI' TextBlock.FontSize='13'/>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property='Foreground' Value='#195AE0' />
<Style.Triggers>
<Trigger Property='IsMouseOver' Value='true'>
<Setter Property='Foreground' Value='Red' />
<Setter Property='Cursor' Value='Hand' />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
You can also change appropriate property for button if it is not important for you:
<Button Focusable="False" Content="Edit" Style="{StaticResource HyperLinkButtonStyle}" Click="EditButton_Click"/>

WPF: Need a nearly "invisible" TabControl. What do I need to override?

For my application, I need a TabControl which will host 2 DataGrids. The control must be as unobtrusive as possible: only the tabs should be seen.
I am told that the solution is somewhere here:
http://msdn.microsoft.com/en-us/library/ms754137.aspx
I guess that I will have to change some value(s) to zero (maybe negative?)
Can you folks provide details?
TIA
I think it's much easier to use a RadioButton than a TabControl
<StackPanel Orientation="Horizontal">
<RadioButton Name="tab1" Content="Tab 1" />
<RadioButton Name="tab2" Content="Tab 2" />
</StackPanel>
<DataGrid>
<DataGrid.Visibility>
<Binding ElementName="tab1" Path="IsChecked">
<Binding.Converter>
<BooleanToVisibilityConverter />
</Binding.Converter>
</Binding>
</DataGrid.Visibility>
</DataGrid>
<DataGrid>
<DataGrid.Visibility>
<Binding ElementName="tab2" Path="IsChecked">
<Binding.Converter>
<BooleanToVisibilityConverter />
</Binding.Converter>
</Binding>
</DataGrid.Visibility>
</DataGrid>

Hide/Show DataGrid based on Selected ListBoxItem in WPF

I have a ListBox:
<ListBox Name="ListB" SelectedIndex="0" ItemsSource="{Binding Account}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="16" Grid.Column="0" Grid.RowSpan="3">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}" >
<Binding Path="AccountNumber" />
<Binding Path="Name" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Based on the AccountNumber I want to Show/Hide DataGrid's that are bound to the ListBoxItems:
<!--DataGrid 1-->
<DataGrid ItemsSource="{Binding ElementName=ListB, Path=SelectedItem}">
..................
</DataGrid>
<!--DataGrid 2-->
<DataGrid ItemsSource="{Binding ElementName=ListB, Path=SelectedItem}">
..................
</DataGrid>
Is there any if/else in WPF? For example
if SelectedItem in ListBox has an AccountNumber 100
than show DataGrid 1 and hide DataGrid 2
else hide DataGrid 1 and show DataGrid 2.
Thank you in advance for the tips.
Unfortunately WPF does not come with if/then/else structures. You have to build up a work-arround or use frameworks, which can solve your issue. One possible solution is to use blend sdk's interaction trigger framework:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
The behavior you mention would be implemented as following:
<i:Interaction.Triggers>
<!-- One Trigger for equal 100 -->
<ei:DataTrigger Binding="{Binding Path=SelectedItem.AccountNumber,
ElementName=ListB}"
Value="100">
<ei:ChangePropertyAction TargetName="DataGrid1"
PropertyName="Visibility"
Value="Collapsed" />
<ei:ChangePropertyAction TargetName="DataGrid2"
PropertyName="Visibility"
Value="Visible" />
</ei:DataTrigger>
<!-- One Trigger for not equal 100 -->
<ei:DataTrigger Binding="{Binding Path=SelectedItem.AccountNumber,
ElementName=ListB}"
Comparison="NotEqual"
Value="100">
<ei:ChangePropertyAction TargetName="DataGrid1"
PropertyName="Visibility"
Value="Visible" />
<ei:ChangePropertyAction TargetName="DataGrid2"
PropertyName="Visibility"
Value="Collapsed" />
</ei:DataTrigger>
</i:Interaction.Triggers>
You will need to include System.Windows.Interactivity.dll into your project references.
Also required would be Microsoft.Expression.Interactions.dll
Another solution would be to bind the visibility of your DataGrids directly to SelectedItem.AccountNumber and attach and IValueConverter, which extracts the Visibility according to logic.
Using the SelectionChanged Event of the ListBox would also work, but becomes pretty much unreadable and may be redundant. If you follow the MVVM approach, your code behind should be almost empty.
This would be straightforward if you were using a MVVM framework.
Add a BooleanToVisibility converter to your View as in this example, with boolean properties to control the visibility of each grid in the ViewModel which are updated whenever the ListBox.SelectedItem is changed.

WPF - Xceed GridControl - saving when edited row has focus

I have an XCeed grid with cell editing enabled.
When i make a change to my cell, leave the row and then save it is persited to the database.
But when i hit my save button when the changed cell is still selected the change doens't get persisted.
How can i make sure when i save the current content is saved?
My Grid xaml:
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource MySource}}"
BorderThickness="1" AutoCreateColumns="False" ReadOnly="False" NavigationBehavior="CellOnly">
<xcdg:DataGridControl.DefaultCellEditors>
<xcdg:CellEditor x:Key="{x:Type system:Boolean}">
<xcdg:CellEditor.EditTemplate>
<DataTemplate>
<xcdg:CheckBox xcdg:Cell.IsCellFocusScope="True"
IsChecked="{xcdg:CellEditorBinding}"
HorizontalContentAlignment="Right"
/>
</DataTemplate>
</xcdg:CellEditor.EditTemplate>
<xcdg:CellEditor.ActivationGestures>
<xcdg:TextInputActivationGesture />
</xcdg:CellEditor.ActivationGestures>
</xcdg:CellEditor>
</xcdg:DataGridControl.DefaultCellEditors>
<xcdg:DataGridControl.Columns>
<xcdg:Column Title="Description" FieldName="Description" ReadOnly="True"/>
<xcdg:Column Title="Start period" FieldName="Start" ReadOnly="True"/>
<xcdg:Column Title="End Period" FieldName="End" ReadOnly="True"/>
<xcdg:Column Title="Finished" FieldName="IsFinished"/>
</xcdg:DataGridControl.Columns>
<!--<xcdg:DataGridControl.Columns>
</xcdg:DataGridControl.Columns>-->
</xcdg:DataGridControl>

Styling columns based on DataGridTemplateColumn in a WPF DataGrid

I am using a WPF DataGrid where one of the columns has a requirement to show an "Edit" hyperlink if the row is editable - this is indicated by a boolean flag in the backing model for the row. I was able to achieve this using a DataGridTemplateColumn - no problems. However an additional requirement on the entire row is not to show any highlights when the row is selected (this is a blue background by default). I have been able to achieve this on other columns by defining the DataGridCell style with a transparent background, e.g.
<DataGridTextColumn
Header="Id"
Binding="{Binding Path=Id}"
HeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
CellStyle="{StaticResource DataGridCellStyle}" />
where DataGridCellStyle is defined as follows:
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent" />
...
</Style>
However the column in question, a DataGridTemplateColumn, does not offer a "CellStyle" attribute which I can use for turning off selection highlights. So my question is how to set the cell style when using a DataGridTemplateColumn? Here's my implementation of the column which satisfies the first requirement (i.e. showing an "Edit" hyperlink if the row is editable):
<DataGridTemplateColumn
Header="Actions"
HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}"
Style="{StaticResource CenterAlignedElementStyle}">
<Hyperlink
Command="..."
CommandParameter="{Binding}">
<TextBlock Text="Edit" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Thanks.
At least in WPF4, there is a CellStyle for DataGridTemplateColumns: http://msdn.microsoft.com/en-us/library/cc189163.aspx

Resources