4
WPF에서 repeatbutton 개체로 작업 할 때 단추가 그래픽 기반이어야합니다 (이미지 브러시 배경 및 테두리 또는 기타 불필요한 효과 없음) .이미지 브러시를 배경으로 사용하는 경우 테두리 및 효과를 WPF 반복 단추에서 제거하는 방법
내가 가지고있는 문제는 내가 무엇을 시도해도 버튼 주위에 흰색 직사각형이 여전히 남아 있으며 몇 시간 동안 이것을 보면서 확신 할 수 없다는 것입니다. 이유 또는 방법을 이해할 수 있습니다. 그것을 제거하십시오.
나는하여 XAML에서 다음을 사용하여 버튼을 생성 한
<RepeatButton Content="" BorderThickness="0" HorizontalAlignment="Left" Margin="334,265,0,0" VerticalAlignment="Top" Width="149" Height="100" Background="{DynamicResource ImageBrush_Decrement}" Style="{DynamicResource RepeatButtonStyle_noflash}" d:LayoutOverrides="HorizontalAlignment"/>
당신이 깜박이는 효과를 일으키는로 나는 (내가 defaultrender을 제거하는 데 사용 "RepeatButtonNoFlash"의 스타일을 참조하고 있습니다 것입니다 이 스타일이
<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>
관련하여 다음과 같이 공유 사전에 정의되어
댄
,
블렌드가 생성 한 템플릿에는 줄이 있습니다. 이것은 당신이 볼 수있는 흰색 테두리를 그리는 것입니다. 내가 게시 한 코드를 보면 ButtonChrome을 제거하고 간단한 테두리로 대체했습니다. 또한 이름 아래에 크롬 테두리를 참조한 컬렉션에서 일부 트리거를 제거해야했습니다. –
Andy
고마워, 나는 단지 내가 이것을 테스트 할 수있는 PC 근처에있어 완벽하게 작동한다 ... 정말 고마워. –