You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何隐藏XamDataGrid的记录选择器箭头但保留记录索引?

解决XamDataGrid隐藏选择器箭头但保留记录索引的方法

嘿,这个需求我之前也折腾过!直接设置XamDataGrid.FieldLayoutSettings.RecordSelectorLocation = RecordSelectorLocation.None;确实会把记录索引和选择器箭头一起干掉,不过咱们换个思路,通过自定义样式就能实现只藏箭头、留编号的效果,具体操作如下:

  • 首先,不要把RecordSelectorLocation设为None,保持它默认的Left(或者你需要的其他位置),这样记录索引才会正常显示出来。
  • 接下来,自定义RecordSelector的控件模板,把模板里负责显示选择器箭头的元素隐藏掉就行。

具体的XAML样式示例

你可以在项目的资源文件或者当前页面的Resources中添加这个样式(记得先引入Infragistics的命名空间):

xmlns:igDP="http://infragistics.com/DataPresenter"

<Style TargetType="{x:Type igDP:RecordSelector}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type igDP:RecordSelector}">
                <Grid>
                    <!-- 保留记录索引的显示控件,这部分负责展示编号 -->
                    <TextBlock x:Name="PART_RecordIndex"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RecordIndex}" />
                    <!-- 把选择器箭头的ToggleButton设为隐藏 -->
                    <ToggleButton x:Name="PART_SelectorButton"
                                  Visibility="Collapsed"
                                  IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如果只想让特定的XamDataGrid生效,不用全局样式的话,可以把样式直接指定到控件的RecordSelectorStyle属性上:

<igDP:XamDataGrid RecordSelectorStyle="{StaticResource YourCustomRecordSelectorStyle}" ...>
    <!-- 其他配置内容 -->
</igDP:XamDataGrid>

这样设置之后,你就能看到记录索引正常显示,而选择器箭头被完美隐藏啦~

内容的提问来源于stack exchange,提问作者Victor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:15:26