我尝试将FocusVisualStyle设为null但没有运气.还有其他方法吗?
<UserControl x:Class="MyControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="373" WIDth="669"> <Expander FocusVisualStyle="{x:Null}" Expanded="expander1_Expanded" Focusable="False" Foreground="DarkBlue" header="My header" Height="219" name="expander1" WIDth="525">.....解决方法 您需要对此部分进行更改(请参阅消息底部的完整模板)
此示例使红色笔划更粗:
`<Style x:Key="ExpanderheaderFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <border> <Rectangle margin="0" SnapsToDevicePixels="true" stroke="Red" strokeThickness="2" strokeDashArray="1 2"/> </border> </ControlTemplate> </Setter.Value> </Setter> </Style>`
这是Blend捕获的扩展器的原始模板 – 它将自动应用于该窗口中的所有扩展器.
`<Window.Resources> <Style x:Key="ExpanderRightheaderStyle" targettype="{x:Type Togglebutton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Togglebutton}"> <border padding="{TemplateBinding padding}"> <GrID Background="transparent" SnapsToDevicePixels="False"> <GrID.RowDeFinitions> <RowDeFinition Height="19"/> <RowDeFinition Height="*"/> </GrID.RowDeFinitions> <GrID> <GrID.Layouttransform> <transformGroup> <transformGroup.Children> <transformCollection> <Rotatetransform Angle="-90"/> </transformCollection> </transformGroup.Children> </transformGroup> </GrID.Layouttransform> <Ellipse x:name="circle" HorizontalAlignment="Center" Height="19" stroke="DarkGray" VerticalAlignment="Center" WIDth="19"/> <Path x:name="arrow" Data="M 1,1.5 L 4.5,5 L 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" stroke="#666" strokeThickness="2" VerticalAlignment="Center"/> </GrID> <ContentPresenter HorizontalAlignment="Center" margin="0,4,0" GrID.Row="1" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="top"/> </GrID> </border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter Property="Data" Targetname="arrow" Value="M 1,4.5 L 4.5,1 L 8,4.5"/> </Trigger> <Trigger Property="IsMouSEOver" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF3C7FB1"/> <Setter Property="stroke" Targetname="arrow" Value="#222"/> </Trigger> <Trigger Property="Ispressed" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF526C7B"/> <Setter Property="strokeThickness" Targetname="circle" Value="1.5"/> <Setter Property="stroke" Targetname="arrow" Value="#FF003366"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpanderUpheaderStyle" targettype="{x:Type Togglebutton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Togglebutton}"> <border padding="{TemplateBinding padding}"> <GrID Background="transparent" SnapsToDevicePixels="False"> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="19"/> <ColumnDeFinition WIDth="*"/> </GrID.ColumnDeFinitions> <GrID> <GrID.Layouttransform> <transformGroup> <transformGroup.Children> <transformCollection> <Rotatetransform Angle="180"/> </transformCollection> </transformGroup.Children> </transformGroup> </GrID.Layouttransform> <Ellipse x:name="circle" HorizontalAlignment="Center" Height="19" stroke="DarkGray" VerticalAlignment="Center" WIDth="19"/> <Path x:name="arrow" Data="M 1,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" stroke="#666" strokeThickness="2" VerticalAlignment="Center"/> </GrID> <ContentPresenter GrID.Column="1" HorizontalAlignment="left" margin="4,0" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Center"/> </GrID> </border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter Property="Data" Targetname="arrow" Value="M 1,4.5"/> </Trigger> <Trigger Property="IsMouSEOver" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF3C7FB1"/> <Setter Property="stroke" Targetname="arrow" Value="#222"/> </Trigger> <Trigger Property="Ispressed" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF526C7B"/> <Setter Property="strokeThickness" Targetname="circle" Value="1.5"/> <Setter Property="stroke" Targetname="arrow" Value="#FF003366"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpanderleftheaderStyle" targettype="{x:Type Togglebutton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Togglebutton}"> <border padding="{TemplateBinding padding}"> <GrID Background="transparent" SnapsToDevicePixels="False"> <GrID.RowDeFinitions> <RowDeFinition Height="19"/> <RowDeFinition Height="*"/> </GrID.RowDeFinitions> <GrID> <GrID.Layouttransform> <transformGroup> <transformGroup.Children> <transformCollection> <Rotatetransform Angle="90"/> </transformCollection> </transformGroup.Children> </transformGroup> </GrID.Layouttransform> <Ellipse x:name="circle" HorizontalAlignment="Center" Height="19" stroke="DarkGray" VerticalAlignment="Center" WIDth="19"/> <Path x:name="arrow" Data="M 1,4.5"/> </Trigger> <Trigger Property="IsMouSEOver" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF3C7FB1"/> <Setter Property="stroke" Targetname="arrow" Value="#222"/> </Trigger> <Trigger Property="Ispressed" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF526C7B"/> <Setter Property="strokeThickness" Targetname="circle" Value="1.5"/> <Setter Property="stroke" Targetname="arrow" Value="#FF003366"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpanderheaderFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <border> <Rectangle margin="0" SnapsToDevicePixels="true" stroke="Black" strokeThickness="1" strokeDashArray="1 2"/> </border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpanderDownheaderStyle" targettype="{x:Type Togglebutton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Togglebutton}"> <border padding="{TemplateBinding padding}"> <GrID Background="transparent" SnapsToDevicePixels="False"> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="19"/> <ColumnDeFinition WIDth="*"/> </GrID.ColumnDeFinitions> <Ellipse x:name="circle" HorizontalAlignment="Center" Height="19" stroke="DarkGray" VerticalAlignment="Center" WIDth="19"/> <Path x:name="arrow" Data="M 1,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="false" stroke="#666" strokeThickness="2" VerticalAlignment="Center"/> <ContentPresenter GrID.Column="1" HorizontalAlignment="left" margin="4,4.5"/> </Trigger> <Trigger Property="IsMouSEOver" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF3C7FB1"/> <Setter Property="stroke" Targetname="arrow" Value="#222"/> </Trigger> <Trigger Property="Ispressed" Value="true"> <Setter Property="stroke" Targetname="circle" Value="#FF526C7B"/> <Setter Property="strokeThickness" Targetname="circle" Value="1.5"/> <Setter Property="stroke" Targetname="arrow" Value="#FF003366"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="StyledExpander" targettype="{x:Type Expander}"> <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.ControlTextBrushKey}}"/> <Setter Property="Background" Value="transparent"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="borderBrush" Value="transparent"/> <Setter Property="borderThickness" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Expander}"> <border borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="true"> <DockPanel> <Togglebutton x:name="headerSite" ContentTemplate="{TemplateBinding headerTemplate}" ContentTemplateSelector="{TemplateBinding headerTemplateSelector}" Content="{TemplateBinding header}" DockPanel.Dock="top" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FocusVisualStyle="{StaticResource ExpanderheaderFocusVisual}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsChecked="{Binding IsExpanded,Mode=TwoWay,relativeSource={relativeSource TemplatedParent}}" margin="1" MinWIDth="0" MinHeight="0" padding="{TemplateBinding padding}" Style="{StaticResource ExpanderDownheaderStyle}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <ContentPresenter x:name="ExpandSite" DockPanel.Dock="Bottom" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </DockPanel> </border> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="true"> <Setter Property="Visibility" Targetname="ExpandSite" Value="Visible"/> </Trigger> <Trigger Property="ExpandDirection" Value="Right"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="Right"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="left"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderRightheaderStyle}"/> </Trigger> <Trigger Property="ExpandDirection" Value="Up"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="top"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="Bottom"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderUpheaderStyle}"/> </Trigger> <Trigger Property="ExpandDirection" Value="left"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="left"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="Right"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderleftheaderStyle}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpanderWithDifferentFocusRectagle" targettype="{x:Type Expander}"> <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.ControlTextBrushKey}}"/> <Setter Property="Background" Value="transparent"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="borderBrush" Value="transparent"/> <Setter Property="borderThickness" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="{x:Type Expander}"> <border borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="true"> <DockPanel> <Togglebutton x:name="headerSite" ContentTemplate="{TemplateBinding headerTemplate}" ContentTemplateSelector="{TemplateBinding headerTemplateSelector}" Content="{TemplateBinding header}" DockPanel.Dock="top" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FocusVisualStyle="{StaticResource ExpanderheaderFocusVisual}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsChecked="{Binding IsExpanded,relativeSource={relativeSource TemplatedParent}}" margin="1" MinWIDth="0" MinHeight="0" padding="{TemplateBinding padding}" Style="{StaticResource ExpanderDownheaderStyle}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <ContentPresenter x:name="ExpandSite" DockPanel.Dock="Bottom" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </DockPanel> </border> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="true"> <Setter Property="Visibility" Targetname="ExpandSite" Value="Visible"/> </Trigger> <Trigger Property="ExpandDirection" Value="Right"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="Right"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="left"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderRightheaderStyle}"/> </Trigger> <Trigger Property="ExpandDirection" Value="Up"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="top"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="Bottom"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderUpheaderStyle}"/> </Trigger> <Trigger Property="ExpandDirection" Value="left"> <Setter Property="DockPanel.Dock" Targetname="ExpandSite" Value="left"/> <Setter Property="DockPanel.Dock" Targetname="headerSite" Value="Right"/> <Setter Property="Style" Targetname="headerSite" Value="{StaticResource ExpanderleftheaderStyle}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static Systemcolors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources>`总结
以上是内存溢出为你收集整理的如何删除WPF(C#)中Expander控件头部的虚线轮廓?全部内容,希望文章能够帮你解决如何删除WPF(C#)中Expander控件头部的虚线轮廓?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)