无法弄清楚为什么某些控件被裁剪

发布于 2024-11-30 13:35:10 字数 5988 浏览 1 评论 0原文

因此,我的按钮超出了它们所在的网格,但它们仅在鼠标悬停时显示。在某些网格中,它们渲染正确,而在某些网格中,它们渲染不正确。哪些是不正确的似乎是一致的,但我无法弄清楚为什么问题会发生在那些特定的网格上。我用 snoop 查看了这些元素,在渲染它们时看不到属性的任何问题。

正确渲染:

在此处输入图像描述

不正确渲染:

在此处输入图像描述

这是代码

<ScrollViewer x:Name="GridItemScroller" Height="300">
    <ItemsControl Margin="0,0" ItemsSource="{Binding Source={StaticResource rowItemsView}}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid VerticalAlignment="Top"  />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="Margin"  Value="{Binding RowIndex, Converter={StaticResource IndexToPositionConverter}, ConverterParameter=20}" />
                <Setter Property="VerticalAlignment" Value="Top" />
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <DataTemplate >
                <Grid x:Name="itemPanel" VerticalAlignment="Top" ClipToBounds="False">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Rectangle Grid.Column="0" Grid.ColumnSpan="2" Fill="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    <CheckBox IsChecked="{Binding Path=Filtered, Converter={StaticResource NotConverter}}" Content="{Binding RowName}" />
                    <Canvas x:Name="CheckBoxButtonPanel" Grid.Column="1" ClipToBounds="False" VerticalAlignment="Center" Width="25" Height="2">
                        <Canvas.Style>
                            <Style TargetType="Canvas">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Setter Property="Panel.ZIndex" Value="0" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=itemPanel, Path=IsMouseOver}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                        <Setter Property="Panel.ZIndex" Value="10" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Canvas.Style>
                        <Button HorizontalAlignment="Right" Height="15" Width="25" Canvas.Top="-15" local:ToolIcon.IconName ="{Binding Source={StaticResource LanguageInfo}, XPath=//Strings/@Up}" local:ToolIcon.Image="pack://application:,,,/CalUI;component/images/Up.png"  
                            Style="{DynamicResource ToolIcon}" Click="Move_Up"/>
                        <Button HorizontalAlignment="Right" Height="15" Width="25" Canvas.Top="2" local:ToolIcon.IconName ="{Binding Source={StaticResource LanguageInfo}, XPath=//Strings/@Down}" local:ToolIcon.Image="pack://application:,,,/CalUI;component/images/Down.png"  
                            Style="{DynamicResource ToolIcon}" Click="Move_Down"/>
                    </Canvas>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>

这是 ToolIcon 样式的 XAML

<Style x:Key="ToolIcon" TargetType="{x:Type Button}">
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid x:Name="ImageGrid">
                    <Grid.Effect>
                        <local:SaturationLuminanceEffect SaturationShift="0.95" LuminanceShift="0.8" />
                    </Grid.Effect>
                    <Image x:Name="image" RenderTransformOrigin="0.5,0.5" Source="{TemplateBinding local:ToolIcon.Image}" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="1" LuminanceShift="1.2" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="1.05" LuminanceShift="1.0" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="0.80" LuminanceShift="1.3" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

So I have buttons that extend beyond the grid they are in, but they only show up on mouse over. In some grids they render correctly and some they are rendered incorrectly. It seems to be consistent which ones are incorrect, but I cannot figure out why the issue occurs on those particular grids. I looked at the elements with snoop and can't see any issues with the properties as they are being rendered.

Correct rendering:

enter image description here

Incorrect rendering:

enter image description here

Here's the code

<ScrollViewer x:Name="GridItemScroller" Height="300">
    <ItemsControl Margin="0,0" ItemsSource="{Binding Source={StaticResource rowItemsView}}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid VerticalAlignment="Top"  />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="Margin"  Value="{Binding RowIndex, Converter={StaticResource IndexToPositionConverter}, ConverterParameter=20}" />
                <Setter Property="VerticalAlignment" Value="Top" />
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <DataTemplate >
                <Grid x:Name="itemPanel" VerticalAlignment="Top" ClipToBounds="False">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Rectangle Grid.Column="0" Grid.ColumnSpan="2" Fill="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    <CheckBox IsChecked="{Binding Path=Filtered, Converter={StaticResource NotConverter}}" Content="{Binding RowName}" />
                    <Canvas x:Name="CheckBoxButtonPanel" Grid.Column="1" ClipToBounds="False" VerticalAlignment="Center" Width="25" Height="2">
                        <Canvas.Style>
                            <Style TargetType="Canvas">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Setter Property="Panel.ZIndex" Value="0" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=itemPanel, Path=IsMouseOver}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                        <Setter Property="Panel.ZIndex" Value="10" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Canvas.Style>
                        <Button HorizontalAlignment="Right" Height="15" Width="25" Canvas.Top="-15" local:ToolIcon.IconName ="{Binding Source={StaticResource LanguageInfo}, XPath=//Strings/@Up}" local:ToolIcon.Image="pack://application:,,,/CalUI;component/images/Up.png"  
                            Style="{DynamicResource ToolIcon}" Click="Move_Up"/>
                        <Button HorizontalAlignment="Right" Height="15" Width="25" Canvas.Top="2" local:ToolIcon.IconName ="{Binding Source={StaticResource LanguageInfo}, XPath=//Strings/@Down}" local:ToolIcon.Image="pack://application:,,,/CalUI;component/images/Down.png"  
                            Style="{DynamicResource ToolIcon}" Click="Move_Down"/>
                    </Canvas>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>

Here's the XAML for the ToolIcon Style

<Style x:Key="ToolIcon" TargetType="{x:Type Button}">
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid x:Name="ImageGrid">
                    <Grid.Effect>
                        <local:SaturationLuminanceEffect SaturationShift="0.95" LuminanceShift="0.8" />
                    </Grid.Effect>
                    <Image x:Name="image" RenderTransformOrigin="0.5,0.5" Source="{TemplateBinding local:ToolIcon.Image}" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="1" LuminanceShift="1.2" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="1.05" LuminanceShift="1.0" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Effect" TargetName="ImageGrid">
                            <Setter.Value>
                                <local:SaturationLuminanceEffect SaturationShift="0.80" LuminanceShift="1.3" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中性美 2024-12-07 13:35:10

@CodeNaked 在评论中提出了以下见解:

剪辑可能是一件棘手的事情。请参阅这个问题以获取有关该主题的更多信息。

@CodeNaked had the following insight in a comment:

Clipping can be a tricky business. See this question for more info on the subject.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文