Home Forums WPF controls Xceed DataGrid for WPF Simple Row MouseOver Colour Change Style

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25803 |

    Hi There,

    I have been looking and trying to get a simple MouseOver row colour change style right but have had no luck, also the code i found in the documentation does not work, saying that the event cannot be found.

    If anyone could help with this i would greatly appreciate it.

    Imported from legacy forums. Posted by Kyle (had 3922 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi :

    in the documentation I look this:

    XAML file
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Orders}”/>

    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <EventSetter Event=”MouseEnter”
    Handler=”DataRowMouseEnter”/>

    <EventSetter Event=”MouseLeave”
    Handler=”DataRowMouseLeave”/>
    </Style>
    </Grid.Resources>

    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}”
    View=”TableView.LunaNormalColorTheme”/>
    </Grid>
    ————————————————————————————————-
    visual basic

    Private Sub DataRowMouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim row As Xceed.Wpf.DataGrid.DataRow = TryCast(sender, Xceed.Wpf.DataGrid.DataRow)

    If Not row Is Nothing Then
    row.Background = Brushes.Pink
    End If

    End Sub
    Private Sub DataRowMouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim row As Xceed.Wpf.DataGrid.DataRow = TryCast(sender, Xceed.Wpf.DataGrid.DataRow)

    If Not row Is Nothing Then
    row.Background = DataGridControl.GetParentDataGridControl(row).Background
    End If

    End Sub
    ————————————————————————————————-
    c#

    private void DataRowMouseEnter( object sender, MouseEventArgs e )
    {
    Xceed.Wpf.DataGrid.DataRow row = sender as Xceed.Wpf.DataGrid.DataRow;

    if( row != null )
    {
    row.Background = Brushes.Pink;
    }

    }
    private void DataRowMouseLeave( object sender, MouseEventArgs e )
    {
    Xceed.Wpf.DataGrid.DataRow row = sender as Xceed.Wpf.DataGrid.DataRow;

    if( row != null )
    {
    row.Background = DataGridControl.GetParentDataGridControl( row ).Background;
    }
    }

    I run the example and Its work!

    Imported from legacy forums. Posted by cams_aries2 (had 716 views)

    User (Old forums)
    Member
    Post count: 23064

    Gah, thank you, i have no idea what happened before, but this works 100’s.

    How would i apply this to the grids themeing capabilities, i have tried attaching the x:Class to the the TableView.x.xaml file, then created a class within the app which corresponds to the x:Class value, but i keep getting:

    Error 1 ‘RollOver’ does not contain a definition for ‘DataRowMouseEnter’ and no extension method ‘DataRowMouseEnter’ accepting a first argument of type ‘RollOver’ could be found (are you missing a using directive or an assembly reference?)

    Error 2 ‘RollOver’ does not contain a definition for ‘DataRowMouseLeave’ and no extension method ‘DataRowMouseLeave’ accepting a first argument of type ‘RollOver’ could be found (are you missing a using directive or an assembly reference?)

    I have no clue what i could be missing :/

    Any help would be appreciated!

    Imported from legacy forums. Posted by Kyle (had 372 views)

    User (Old forums)
    Member
    Post count: 23064

    Nevermind, added it by adding in the DataTemplate for Row, and creating a Trigger – No C# Code Required:

    =======================================================

    <!–**************************
    * TEMPLATE: Row
    ************************** –>
    <ControlTemplate x:Key=”tableViewRowTemplate”
    TargetType=”xcdg:Row”>
    <!– A basic Row Template requires at least a Panel named “PART_CellsHost” to which the Row’s cells will be added.
    This Panel is usually placed inside a Border who is responsible for painting the gridlines. –>

    <!– This Grid is used to layout the GroupLevelIndicatorPane placeholder and the CellsHost panel. –>
    <Grid x:Name=”rootGrid”>
    <Grid.ColumnDefinitions>
    <!– GroupLevelIndicatorPane –>
    <ColumnDefinition Width=”Auto” />

    <!– CellsHost panel –>
    <ColumnDefinition Width=”*” />
    </Grid.ColumnDefinitions>

    <!– The border responsible for the visual outline of the row (gridlines and background)
    spans the GroupLevelIndicatorPane and CellsHost Panel. Those 2 elements are not children of
    the Border because we don’t want the border to be displayed in the GroupLevelIndicatorPane. –>
    <Border x:Name=”rootBorder”
    Grid.Column=”0″
    Grid.ColumnSpan=”2″
    Background=”{TemplateBinding Background}”
    BorderBrush=”{TemplateBinding BorderBrush}”
    BorderThickness=”{TemplateBinding BorderThickness}”
    Padding=”{TemplateBinding Padding}” />

    <!– GroupLevelIndicatorPane is a placeholder for individual GroupLevelIndicator elements that are added
    whenever this Row is part of a group. –>
    <xcdg:GroupLevelIndicatorPane x:Name=”groupLevelIndicatorPane”
    xcdg:TableView.CanScrollHorizontally=”False”
    Grid.Column=”0″ />

    <!– The PART_CellsHost part designates the Panel to which this Row’s Cells should be added.–>
    <xcdg:FixedCellPanel x:Name=”PART_CellsHost”
    Grid.Column=”1″
    FixedCellCount=”{xcdg:ViewBinding FixedColumnCount, Mode=TwoWay}”
    SplitterStyle=”{TemplateBinding xcdg:TableView.FixedColumnSplitterStyle}”
    SplitterWidth=”{xcdg:ViewBinding FixedColumnSplitterWidth}”
    ShowSplitter=”{xcdg:ViewBinding ShowFixedColumnSplitter}”
    FixedColumnDropMarkPen=”{xcdg:ViewBinding FixedColumnDropMarkPen}”
    Margin=”{TemplateBinding BorderThickness}”/>

    </Grid>

    <ControlTemplate.Triggers>

    <!– When changing the appearance (e.g. background/foreground) of the Row to reflect specific
    states (e.g. IsSelected), it is recommended to apply the changes directly to the template
    elements because we want those modifications to be effective even when a value has been
    explicitely set to these properties on the TemplatedParent. Also, when someone queries
    the value of these properties on the TemplatedParent, we don’t want to return the
    intermediate, state-specific values. –>

    <color=”red”><Trigger Property=”IsMouseOver” Value=”True”>
    <Setter Property=”Background” Value=”{StaticResource HoverBrush}”/>
    <Setter Property=”Foreground” Value=”White”/>
    </Trigger></color>

    <!– When the Row is Selected, we want to change its background/foreground to the appropriate brushes. –>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>

    <Condition Binding=”{Binding RelativeSource={RelativeSource Self},Path=IsSelected}”
    Value=”True”/>

    <Condition Binding=”{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=xcdg:DataGridControl},Path=IsKeyboardFocusWithin}”
    Value=”True”/>

    </MultiDataTrigger.Conditions>

    <Setter TargetName=”rootBorder”
    Property=”Background”
    Value=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectionBackground}” />

    <Setter TargetName=”rootGrid”
    Property=”TextElement.Foreground”
    Value=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=SelectionForeground}” />

    </MultiDataTrigger>

    <!– When the Row is Selected but the parent DataGridControl is not focused, we want to change
    the Row’s background/foreground to the appropriate brushes. –>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>

    <Condition Binding=”{Binding RelativeSource={RelativeSource Self},Path=IsSelected}”
    Value=”True”/>

    <Condition Binding=”{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=xcdg:DataGridControl},Path=IsKeyboardFocusWithin}”
    Value=”False”/>

    <Condition Binding=”{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=xcdg:DataGridControl},Path=HideSelection}”
    Value=”False” />

    </MultiDataTrigger.Conditions>

    <Setter TargetName=”rootBorder”
    Property=”Background”
    Value=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=InactiveSelectionBackground}” />

    <Setter TargetName=”rootGrid”
    Property=”TextElement.Foreground”
    Value=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=InactiveSelectionForeground}” />

    </MultiDataTrigger>

    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>

    Imported from legacy forums. Posted by Kyle (had 6330 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.