【问题标题】:Button styling for SilverlightSilverlight 的按钮样式
【发布时间】:2011-12-06 01:58:20
【问题描述】:

我正在尝试将控件样式设置为类似于 silverlight 中的选项卡控件,用于嵌入的窗口。

我从按钮开始,将它们设置为看起来像标签项。

我遇到的问题是我想要一个“活动”选项卡的概念,并由此更改活动选项卡项目的颜色或更改非活动选项卡的颜色。我曾想过添加一个自定义的“活动”视觉状态可能是一种选择,但我是 silverlight 的新手,所以这可能是不正确的。

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:local="clr-namespace:WindowsEmbeddedSilverlightApplication1"
x:Class="WindowsEmbeddedSilverlightApplication1.MainPage"
Width="800" Height="480">

<UserControl.Resources>
    <Style x:Key="TabItemFirst" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Background="#FFC5EEFF" CornerRadius="5,5,0,0" BorderBrush="Black" BorderThickness="1">                          
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="TabItemNext" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Background="#C8E9F7" Margin="-1,0,0,0" CornerRadius="5,5,0,0" BorderBrush="Black" BorderThickness="1">
                        <ContentPresenter  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>                       
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White">

    <StackPanel Orientation="Horizontal">
        <Button Canvas.ZIndex="3" Width="75" Height="25" Style="{StaticResource TabItemFirst}" Content="Left"/>
        <Button Canvas.ZIndex="2" Width="75" Height="25" Style="{StaticResource TabItemNext}" Content="Center"/>
        <Button Canvas.ZIndex="1" Width="75" Height="25" Style="{StaticResource TabItemNext}" Content="Right"/>
    </StackPanel>

</Grid>
</UserControl>

任何有关如何实现此功能的指针将不胜感激。

【问题讨论】:

    标签: silverlight


    【解决方案1】:

    【讨论】:

    • 嗨,谢谢。查看 ToggleButton 样式 xaml 很有帮助,但它不允许控件在单击另一个控件时保留状态。 IE。页面上不相关的控件。我想我需要添加一个新状态并能够使用与每个选项卡项关联的这个值来了解它是否应该具有不同的外观。
    猜你喜欢
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多