将路径描边颜色绑定到前景
在 Blend 中使用 Silverlight 的 TabControl
元素创建了以下标记:
<controls:TabControl>
<controls:TabItem Header="TabItem" Style="{StaticResource TabItemStyle1}" />
<controls:TabItem Style="{StaticResource TabItemStyle1}">
<controls:TabItem.Header>
<StackPanel Orientation="Horizontal">
<Path Data="M0,14L0,6 5,0 10,6 10,14 0,6 10,6 0,14 10,14"
StrokeLineJoin="Round" Margin="0 0 6 0"
Stroke="Black"/>
<TextBlock Text="TabItem"/>
</StackPanel>
</controls:TabItem.Header>
</controls:TabItem>
</controls:TabControl>
TabItemStyle1
是 TabItem
默认样式的副本。 我通过在 MouseOver
情节提要中添加颜色动画来更改 TabItemStyle1
,以便当鼠标悬停在未选定的选项卡项上时它们会变成红色:
<ColorAnimation BeginTime="0" Duration="00:00:00.001"
Storyboard.TargetName="HeaderTopUnselected"
Storyboard.TargetProperty="(UIElement.Foreground).(SolidColorBrush.Color)"
To="Red" />
现在,当我悬停第二个选项卡时,文本会变为红色红色但路径保持黑色:
我应该如何定义路径描边颜色以使其遵循相同的规则?
Using the TabControl
element for Silverlight in Blend I created the following markup:
<controls:TabControl>
<controls:TabItem Header="TabItem" Style="{StaticResource TabItemStyle1}" />
<controls:TabItem Style="{StaticResource TabItemStyle1}">
<controls:TabItem.Header>
<StackPanel Orientation="Horizontal">
<Path Data="M0,14L0,6 5,0 10,6 10,14 0,6 10,6 0,14 10,14"
StrokeLineJoin="Round" Margin="0 0 6 0"
Stroke="Black"/>
<TextBlock Text="TabItem"/>
</StackPanel>
</controls:TabItem.Header>
</controls:TabItem>
</controls:TabControl>
TabItemStyle1
is a copy of the default style of a TabItem
.
I altered TabItemStyle1
by adding a color animation in the MouseOver
storyboard so that unselected tab items become red when the mouse hovers them:
<ColorAnimation BeginTime="0" Duration="00:00:00.001"
Storyboard.TargetName="HeaderTopUnselected"
Storyboard.TargetProperty="(UIElement.Foreground).(SolidColorBrush.Color)"
To="Red" />
Now when I hover the second tab, the text becomes red but the Path remains black:
How should I define the Path Stroke color to make it follow the same rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以下应该有效:
The following should work:
这不是一个完美的解决方案,但你可以使用这个
it's not a perfect solution but you could use this
尝试像这样绑定到 TemplatedParent:
我还没有测试过这个,但是尝试一下并让我知道。如果它不起作用,请尝试以下操作:
我有一种感觉,Color 属性需要成为绑定的源,而不是实际的画笔。
Try binding to the TemplatedParent like this:
I haven't tested this, but give it a whirl and let me know. If it doesn't work, try this:
I have a feeling that the Color property needs to be the source of binding, not the actual brush.
我通过将标题内容画笔绑定到
{TemplateBinding TextElement.Foreground}
来使其工作。在其他情况下,我使用标准属性与转换器绑定,例如,如果我必须使元素的画笔适应项目状态。
I made it work by binding the header content brushes to
{TemplateBinding TextElement.Foreground}
.In other cases I used standard property binding with converters, for example if I had to adapt element's brushes to item state.
// 动画
//************************************************ **
// animazione periferica
//**********************************************