【问题标题】:Devexpress- Background and grid lines in a gridcontrolDevexpress-gridcontrol 中的背景和网格线
【发布时间】:2015-11-08 18:32:19
【问题描述】:

我遇到了一些关于 gridcontrol 的问题。

我必须使用填充、颜色、字体和悬停效果来设置网格列的样式和格式。

<Style x:Key="SelectedRowStyle" TargetType="{x:Type dxg:RowControl}">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontFamily" Value="pack://application:,,,/PA.Tos.UI;component/ResourceDictionaries/#Brandon Grotesque Black" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontWeight" Value="Regular" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding 
                ElementName=GroupCodeListView,Path=DataContext.SelectedGroupCode.Deleted, 
                UpdateSourceTrigger=PropertyChanged}" Value="true">
                    <Setter Property="Background" Value="Red" />
                    <Setter Property="Foreground" Value="Black" />
                </DataTrigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource HoverRowBorderColor}" />
                    <Setter Property="Foreground" Value="Black" />
                </Trigger>
                <Trigger Property="dxg:GridViewBase.IsFocusedRow" Value="True">
                    <Setter Property="Background" Value="{StaticResource HoverRowBorderColor}" />
                    <Setter Property="BorderBrush" Value="{StaticResource HoverStrokeColor}" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="Foreground" Value="Black" />

                </Trigger>
            </Style.Triggers>
        </Style>


        <Style x:Key="CustomCellStyle" BasedOn="{StaticResource {dxgt:GridRowThemeKey 
          ResourceKey=LightweightCellStyle}}" TargetType="{x:Type dxg:LightweightCellEditor}">
            <Setter Property="MaxHeight" Value="25"/>
            <Setter Property="MinHeight" Value="25"/>
            <Style.Triggers>

            </Style.Triggers>
  1. 为了响应鼠标悬停或行选择,我必须将所有网格线的边框设置为蓝色。只有底部的网格线是蓝色的 现在从上面。适用于 cellcontent Presenter 的代码在这里无法实现。

  2. 为了响应单击的垃圾桶图标,我必须为特定行显示浅红色背景。 我将(viewmodel 属性)SelectedGroupCode.Deleted=true 绑定到后台。绑定在代码中显示。 但除了有问题的行之外,所有行都被涂成红色。

  3. 必须设置网格线宽度。我已经设法仅使用 gridrowthemekey_rowcontrolcontainertemplate 将其设置为水平线。

我向您保证,我已经阅读了之前的一些帖子,但是对于 Scrum sprint 来说它花费了太多时间。

缺少什么?

【问题讨论】:

  • 不清楚你是如何在GridControl 中使用这种风格的?
  • 我正在将行样式和单元格样式设置为上述样式。

标签: wpf devexpress gridcontrol


【解决方案1】:

如果您想更改单元格样式以响应鼠标悬停,则可以在DataTrigger 的绑定中使用RelativeSource 标记扩展。如果要检查该行是否获得焦点,则可以使用RowData.IsFocused 属性。
这是一个例子:

<Style x:Key="CustomCellStyle" TargetType="{x:Type dxg:LightweightCellEditor}" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=LightweightCellStyle}}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type dxg:RowControl}}}" Value="True">
            <Setter Property="BorderBrush" Value="Blue" />
        </DataTrigger>
        <DataTrigger Binding="{Binding RowData.IsFocused}" Value="true">
            <Setter Property="BorderBrush" Value="Blue" />
        </DataTrigger>
    </Style.Triggers>
</Style>

为了显示特定行的自定义样式,我建议您使用Conditional Formatting
这是一个例子:

<dxg:GridControl ...>
    ...
    <dxg:GridControl.View>
        <dxg:TableView>
            <dxg:TableView.FormatConditions>                    
                <dxg:FormatCondition Expression="[Deleted]" FieldName="Profit">
                    <dxc:Format Foreground="Red"/>
                </dxg:FormatCondition>
            </dxg:TableView.FormatConditions>
        </dxg:TableView>
    </dxg:GridControl.View>
</dxg:GridControl>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    相关资源
    最近更新 更多