添加触发器到切换按钮样式-> XML
你好 我想添加触发器来混合生成的 XML。我在混合中创建了切换按钮,现在我想添加触发器属性以在选中按钮时切换前景(否则为蓝色,白色)。 这是我的 XML(在 VS 2010 中粘贴和使用)
<Border x:Name="border" BorderBrush="Transparent" BorderThickness="1" CornerRadius="7,7,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF024592"/>
<GradientStop Color="#FF003D8B" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Tag}" Margin="5,5,0,5"/>
<ContentPresenter Grid.Column="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hi
I want to add Triggers to blend generated XML.I created Toggle button in blend now i want to add trigger properties to toggle the foreground when the button is checked (Blue ,white otherwise).
Here goes my XML (pasted and using in VS 2010)
<Border x:Name="border" BorderBrush="Transparent" BorderThickness="1" CornerRadius="7,7,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF024592"/>
<GradientStop Color="#FF003D8B" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Tag}" Margin="5,5,0,5"/>
<ContentPresenter Grid.Column="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加了前台触发器。还在内容文本左侧添加了一个
Image
绑定到ToggleButton
的 Tag 属性。您还可以子类化ToggleButton
并添加BitmapImage
属性,或者如果您不想使用 TagUseable 之类的,则可以使用附加属性(在边框中使用此代码将有所帮助)它会扩大)
Added Trigger for Foreground. Also added an
Image
to the left of the Content Text binding to the Tag property ofToggleButton
. You could also subclassToggleButton
and add aBitmapImage
property or use an Attached Property if you don't want to use TagUseable like(using this code in border will help other wise it would expand)