c# – 当画笔用作背景时,如何从WPF重复按钮中删除边框和效果

c# – 当画笔用作背景时,如何从WPF重复按钮中删除边框和效果,第1张

概述我正在使用 WPF中的repeatbutton对象,该按钮需要基于图形(图像画笔背景,没有边框或其他多余的效果). 我遇到的问题是,无论我尝试什么,按钮周围仍然有一个白色矩形,而且,我不确定现在看了几个小时之后,我确信我理解为什么或如何删除它. 我在XAML中使用以下内容创建了按钮 <RepeatButton Content="" BorderThickness="0" HorizontalAli @H_419_1@ 我正在使用 WPF中的repeatbutton对象,该按钮需要基于图形(图像画笔背景,没有边框或其他多余的效果).

我遇到的问题是,无论我尝试什么,按钮周围仍然有一个白色矩形,而且,我不确定现在看了几个小时之后,我确信我理解为什么或如何删除它.

我在XAML中使用以下内容创建了按钮

<Repeatbutton Content="" borderThickness="0" HorizontalAlignment="left" margin="334,265,0" VerticalAlignment="top" WIDth="149" Height="100" Background="{DynamicResource ImageBrush_Decrement}" Style="{DynamicResource RepeatbuttonStyle_noflash}" d:LayoutOverrIDes="HorizontalAlignment"/>

你会注意到我引用了一个“RepeatbuttonNoFlash”样式,我用它来删除defaultrender(因为它引起了闪烁效果,这种样式在共享字典中定义如下

<ResourceDictionary    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_windows_themes="clr-namespace:Microsoft.windows.themes;assembly=PresentationFramework.Aero">    <Style x:Key="buttonFocusVisual">        <Setter Property="Control.Template">            <Setter.Value>                <ControlTemplate>                    <Rectangle margin="2" SnapsToDevicePixels="true" stroke="{DynamicResource {x:Static Systemcolors.ControlTextBrushKey}}" strokeThickness="0" strokeDashArray="1 2"/>                </ControlTemplate>            </Setter.Value>        </Setter>    </Style>    <!-- Resource dictionary entrIEs should be defined here. -->    <Style x:Key="BasebuttonStyle" targettype="{x:Type buttonBase}">        <Setter Property="FocusVisualStyle" Value="{StaticResource buttonFocusVisual}"/>        <Setter Property="Background" Value="transparent"/>        <Setter Property="borderBrush" Value="transparent"/>        <Setter Property="borderThickness" Value="0"/>        <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.ControlTextBrushKey}}"/>        <Setter Property="HorizontalContentAlignment" Value="Center"/>        <Setter Property="VerticalContentAlignment" Value="Center"/>        <Setter Property="padding" Value="0"/>        <Setter Property="Template">            <Setter.Value>                <ControlTemplate targettype="{x:Type buttonBase}">                    <Microsoft_windows_themes:buttonChrome x:name="Chrome" Background="{TemplateBinding Background}" RenderMouSEOver="False" Renderpressed="{TemplateBinding Ispressed}" RenderDefaulted="False" SnapsToDevicePixels="true" Style="{DynamicResource buttonChromeStyle_noborder}">                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                    </Microsoft_windows_themes:buttonChrome>                    <ControlTemplate.Triggers>                        <Trigger Property="IsKeyboardFocused" Value="true">                            <Setter Property="RenderDefaulted" Targetname="Chrome" Value="true"/>                        </Trigger>                        <Trigger Property="Togglebutton.IsChecked" Value="true">                            <Setter Property="Renderpressed" Targetname="Chrome" Value="true"/>                        </Trigger>                        <Trigger Property="IsEnabled" Value="false">                            <Setter Property="Foreground" Value="#ADADAD"/>                        </Trigger>                    </ControlTemplate.Triggers>                </ControlTemplate>            </Setter.Value>        </Setter>    </Style>    <Style x:Key="RepeatbuttonStyle_noflash" BasedOn="{StaticResource BasebuttonStyle}" targettype="{x:Type Repeatbutton}">        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>    </Style></ResourceDictionary>

问候

解决方法 它来自Microsoft_windows_themes:buttonChrome尝试用边框或其他东西替换它,应该摆脱它.

<Style x:Key="BasebuttonStyle" targettype="{x:Type buttonBase}">        <Setter Property="FocusVisualStyle" Value="{StaticResource buttonFocusVisual}"/>        <Setter Property="Background" Value="transparent"/>        <Setter Property="borderBrush" Value="transparent"/>        <Setter Property="borderThickness" Value="0"/>        <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.ControlTextBrushKey}}"/>        <Setter Property="HorizontalContentAlignment" Value="Center"/>        <Setter Property="VerticalContentAlignment" Value="Center"/>        <Setter Property="padding" Value="0"/>        <Setter Property="Template">            <Setter.Value>                <ControlTemplate targettype="{x:Type buttonBase}">                    <border Background="{TemplateBinding Background}">                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                    </border>                    <ControlTemplate.Triggers>                        <Trigger Property="IsEnabled" Value="false">                            <Setter Property="Foreground" Value="#ADADAD"/>                        </Trigger>                    </ControlTemplate.Triggers>                </ControlTemplate>            </Setter.Value>        </Setter></Style>
总结

以上是内存溢出为你收集整理的c# – 当画笔用作背景时,如何从WPF重复按钮中删除边框和效果全部内容,希望文章能够帮你解决c# – 当画笔用作背景时,如何从WPF重复按钮中删除边框和效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1228981.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存