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

WPF Telerik RadGridView筛选弹窗宽度调整需求求助

调整WPF Telerik RadGridView筛选弹窗(FilterPopup)宽度的方案

方案1:重写FilterPopup模板实现拖拽调整宽度

Telerik RadGridView的FilterPopup默认未暴露直接的宽度调整属性,你可以通过重写其ControlTemplate添加拖拽逻辑,模拟列宽调整的交互:

  1. 定义带拖拽手柄的FilterPopup样式模板:
<Style TargetType="telerik:FilterPopup">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="telerik:FilterPopup">
                <Popup x:Name="PART_Popup"
                       Width="{TemplateBinding Width}"
                       Placement="Bottom"
                       IsOpen="{TemplateBinding IsOpen}">
                    <Grid x:Name="PopupGrid" Width="{TemplateBinding Width}">
                        <!-- 原有筛选内容容器 -->
                        <ContentPresenter x:Name="PART_ContentPresenter" Content="{TemplateBinding Content}"/>
                        <!-- 拖拽调整手柄 -->
                        <Border x:Name="ResizeHandle"
                                Width="5"
                                Background="Transparent"
                                Cursor="SizeWE"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Stretch">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseLeftButtonDown">
                                    <local:ResizePopupTriggerAction TargetPopup="{Binding ElementName=PART_Popup}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Border>
                    </Grid>
                </Popup>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
  1. 实现拖拽调整的行为类:
public class ResizePopupTriggerAction : TriggerAction<UIElement>
{
    public Popup TargetPopup { get; set; }
    private double _startWidth;
    private double _startMouseX;

    protected override void Invoke(object parameter)
    {
        if (TargetPopup == null) return;
        var mouseArgs = parameter as MouseButtonEventArgs;
        _startWidth = TargetPopup.ActualWidth;
        _startMouseX = mouseArgs.GetPosition(null).X;
        Mouse.Capture(AssociatedObject);
        AssociatedObject.MouseMove += OnMouseMove;
        AssociatedObject.MouseLeftButtonUp += OnMouseLeftButtonUp;
    }

    private void OnMouseMove(object sender, MouseEventArgs e)
    {
        if (TargetPopup == null) return;
        var deltaX = e.GetPosition(null).X - _startMouseX;
        TargetPopup.Width = Math.Max(200, _startWidth + deltaX); // 设置最小宽度避免弹窗过小
    }

    private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        AssociatedObject.ReleaseMouseCapture();
        AssociatedObject.MouseMove -= OnMouseMove;
        AssociatedObject.MouseLeftButtonUp -= OnMouseLeftButtonUp;
    }
}

方案2:后台代码设置固定宽度

如果仅需固定宽度而非拖拽调整,可在RadGridView的FilterOpened事件中获取弹窗实例修改宽度:

private void RadGridView_FilterOpened(object sender, Telerik.Windows.Controls.GridView.GridViewFilterEventArgs e)
{
    var filterPopup = e.Column.ColumnFilterPopup as FilterPopup;
    if (filterPopup != null)
    {
        filterPopup.Width = 300; // 替换为你需要的宽度值
        // 若需适配内容,可绑定内容实际宽度:
        // filterPopup.Width = filterPopup.Content.ActualWidth + 20;
    }
}

注意事项

  • 需引用Telerik命名空间:xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
  • 方案1中的交互逻辑需引用Microsoft.Xaml.Behaviors.Wpf或System.Windows.Interactivity

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 01:35:03