在我的Windows商店App中,我正在尝试创建按钮样式,例如导航后退按钮。所以我创建了一个ButtonStyle,它包含一个Path(一个圆圈)和一个ContentPresenter。
App.xaml的ResourceDictionary内部:
<Style x:Key="CnSCircleButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Circle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonPointerOverBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Circle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarItemForegroundThemeBrush}" />
<!-- Can I access the Fill property of the Path inside Button and set it to Black? -->
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border"
Margin="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Path x:Name="Circle"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="Transparent"
Stroke="White"
StrokeThickness="2"
UseLayoutRounding="False">
<Path.Data>
<EllipseGeometry Center="20, 20"
RadiusX="20"
RadiusY="20" />
</Path.Data>
</Path>
<ContentPresenter x:Name="ContentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在页面内:
<Button Width="45"
Height="45"
Margin="0 0 0 20"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="Transparent"
BorderThickness="0"
Command="{Binding LoginCommand}"
Style="{StaticResource CnSCircleButtonStyle}">
<Grid Width="44" Height="44">
<Path Name="Test"
Width="20"
Height="20"
Margin="0 0 23 5"
Data="{StaticResource tickIcon}"
Fill="White"
Stretch="Uniform" />
</Grid>
</Button>
所以在按下时我可以轻松填充白色圆圈路径。但我也希望Button里面的Path充满Black。所以我的问题是:当VisualState被按下以搜索ContentPresenter时是否有任何方法在xaml中是否存在任何方法?如果内部有一个Path子句,则将其Fill属性设置为黑色?