我正在WPF用戶控件,本質上是一個pimped-up Expander控件。爲了讓控制器看起來完全相同,無論它是在Windows Classic還是Aero主題上運行,我都設法設置了一個控制模板,它幾乎可以模擬上/下箭頭。WPF路徑/「向上」箭頭得到2px切掉
「向下」箭頭看起來應該完全一樣。但是,「向上」箭頭得到[似乎是2個像素砍掉,這使得它看起來有點圓,我想修復:
以下是完整<Path>
標記:
<Path x:Name="arrow"
Margin="0,5,0,0"
Stroke="SteelBlue"
Data="M 0 5 L 5 0 L 10 5"
StrokeThickness="2"
Height="10" Width="10" />
我想知道如何改變以獲得我的兩個像素 - 我試圖調整邊距和高度,但沒有運氣。我相信這只是一個小小的調整,缺少了什麼,只是無法弄清楚什麼和確切的地方。任何人?
另外我需要弄清楚爲什麼頂部邊框看起來歪斜......但這超出了這個問題的範圍!
編輯 - 這裏有足夠的標記來重現風格;如果刪除Margin
,Height
和Width
並對準箭頭數據集中也不會剪輯Path
數據應用樣式NormalExpander
到Expander
控制,你會看到我所看到的...
<Style x:Key="ExpanderDownHeaderStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Padding="{TemplateBinding Padding}">
<Grid SnapsToDevicePixels="False" Height="25">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse x:Name="circle" HorizontalAlignment="Center" Height="19" Stroke="SteelBlue" VerticalAlignment="Center" Width="19"/>
<Path x:Name="arrow" Margin="0,5,0,0" Stroke="SteelBlue" Data="M 0 5 L 5 0 L 10 5" StrokeThickness="2" Height="10" Width="10" />
<!-- down arrow: M 0 0 L 5 5 L 10 0 -->
<ContentPresenter Grid.Column="1" HorizontalAlignment="Left" RecognizesAccessKey="True" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<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="DarkBlue"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Data" TargetName="arrow" Value="M 0 5 L 5 0 L 10 5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NormalExpander" TargetType="Expander">
<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}" 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="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="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
找到了一個解決方案 - 使用路徑上:M 1 4 L 5 0 L 9 4 |向下:M 1 0 L 5 4 L 9 0'使得一個更緊的箭頭,不會被剪切。我仍然不知道是什麼導致了剪輯,但我會用盡快的小箭頭。 –