开发者

How do you style the label for a Silverlight ToggleSwitch?

I am wanting to change the foreground colour of a Silverlight ToggleSwitch, although when i open the object in ExpressionBlend i have no object items to edit.

How is this done? (without rebuildi开发者_C百科ng OR using reflector)?


I am not quite sure what you are doing wrong in Blend, however, you can see the template for the ToggleSwitch if you look at the sourcecode for ToggleSwitch here:

http://silverlight.codeplex.com/SourceControl/changeset/view/61620#1325059

Ignoring the storyboards / VisualStateManager, the control has the following markup:

<Grid x:Name="SwitchRoot" Background="Transparent" Height="95" Width="136">
    <Grid x:Name="SwitchTrack" Width="88">
    <Grid x:Name="SwitchBottom" Background="{TemplateBinding SwitchForeground}" Height="32">
        <Rectangle
        x:Name="SwitchBackground"
        Fill="{TemplateBinding Background}"
        Width="76"
        Height="20"
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Rectangle.RenderTransform>
            <TranslateTransform x:Name="BackgroundTranslation"/>
        </Rectangle.RenderTransform>
        </Rectangle>
        <Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="2">
        <Border BorderBrush="{StaticResource PhoneBackgroundBrush}" BorderThickness="4"/>
        </Border>
    </Grid>
    <Border
        x:Name="SwitchThumb"
        BorderBrush="{StaticResource PhoneBackgroundBrush}"
        BorderThickness="4,0"
        Margin="-4,0"
        Width="28"
        Height="36"
        HorizontalAlignment="Left">
        <Border.RenderTransform>
        <TranslateTransform x:Name="ThumbTranslation"/>
        </Border.RenderTransform>
        <Border
        x:Name="ThumbCenter"
        BorderBrush="{StaticResource PhoneForegroundBrush}"
        BorderThickness="2"
        Background="White"/>
    </Border>
    </Grid>
</Grid>

I would suggest using a different colour where the resource PhoneForegroundBrush is used.


I think you will need to define a new Template for the control and then change your style as you see fit.

You can do this by right clicking on your control and select Edit Template and then create your Edit a Copy. This will create a new Style for you that you can change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜