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

如何移除Infragistics XamMonthView中的‘Click to add event’按钮?

移除XamMonthCalendar中悬停日期的“Click to add event”按钮解决路径

问题背景

需要移除Infragistics XamMonthCalendar(对应控件模板中的igSchedule:XamMonthView)里,鼠标悬停日期单元格一秒后弹出的“Click to add event”按钮,已获取XamMonthView的基础模板,但需深入修改内部日期单元格的模板。


具体解决步骤

  • 定位目标元素:该添加按钮属于日期单元格控件igSchedule:DayCell,而非直接在XamMonthView模板中。ScheduleStackPanel负责渲染日期单元格,因此需修改DayCell的控件模板。
  • 提取DayCell默认模板:在Visual Studio或Blend中,找到igSchedule:DayCell控件,右键选择「编辑模板」→「编辑副本」,生成包含完整结构的DayCell模板代码。
  • 移除添加按钮:在生成的DayCell模板中,找到对应“Click to add event”的元素(通常命名为AddEventButton或类似标识的Button/ContentControl),将其Visibility属性设为Collapsed,或直接删除该元素节点。
  • 关联修改后的模板到XamMonthView:在你已有的XamMonthView样式中,添加Setter指定修改后的DayCellStyle。

代码示例

1. 修改后的DayCell样式

<Style x:Key="CustomDayCellStyle" TargetType="{x:Type igSchedule:DayCell}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type igSchedule:DayCell}">
                <!-- 保留DayCell原有其他结构 -->
                <!-- ... 省略原有模板中的其他元素 ... -->
                <!-- 找到并修改添加按钮的Visibility -->
                <Button x:Name="AddEventButton" 
                        Visibility="Collapsed" 
                        <!-- 省略原有按钮的其他属性 --> />
                <!-- ... 省略剩余模板结构 ... -->
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

2. 更新XamMonthView样式关联自定义DayCellStyle

<Style TargetType="{x:Type igSchedule:XamMonthView}">
    <Setter Property="FontFamily" Value="Segoe UI"/>
    <Setter Property="Background" Value="Transparent"/>
    <!-- 添加此行关联自定义DayCell样式 -->
    <Setter Property="DayCellStyle" Value="{StaticResource CustomDayCellStyle}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type igSchedule:XamMonthView}">
                <!-- 保留你原有的XamMonthView模板结构 -->
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                    <Grid x:Name="RootPanel">
                        <ig:GridBagPanel SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <igSchedulePrim:ScheduleStackPanel x:Name="GroupHeadersPanel" Visibility="{TemplateBinding CalendarHeaderAreaVisibilityResolved}"/>
                            <igSchedulePrim:ScheduleStackPanel x:Name="GroupsPanel"/>
                            <ScrollBar x:Name="WeekScrollBar" Orientation="Vertical" Style="{TemplateBinding ScrollBarStyle}"/>
                            <ScrollBar x:Name="TimeslotGroupScrollBar" Orientation="Horizontal" Style="{TemplateBinding ScrollBarStyle}"/>
                        </ig:GridBagPanel>
                        <ContentControl x:Name="ErrorDisplay" Content="{Binding BlockingError, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource BlockingErrorStyle}" Visibility="Collapsed"/>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

注意事项

  • 确保XAML中已正确引用Infragistics的命名空间,例如:
    xmlns:ig="http://infragistics.com/Controls"
    xmlns:igSchedule="http://infragistics.com/Schedule"
    xmlns:igSchedulePrim="http://infragistics.com/SchedulePrimitives"
    
  • 若无法通过名称定位添加按钮,可通过Visual Studio的「Live Visual Tree」工具查看悬停时弹出元素的名称和结构。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 12:40:43