views:

75

answers:

1

I have a onetime Style and corresponding ControlTemplate for a custom HyperLinkButton in Blend 4 (for Silverlight).

Documentation for Blend says :

Control templates are wrapped inside styles so that the style that is applied to a control includes both the appearance (parts) and the behavior for the control. (from here) and (also here)

So I click my HyperlinkButton on the artboard and select Object > Edit Template > Edit a copy and I get:

<HyperlinkButton Template="{StaticResource HyperlinkButtonControlTemplate}"/>

Well thats not wrapped in a style is it!

SO I start over again and try to create a style with Object > Edit Style > Edit a copy and that gives me a new style, but no template (as expected):

<Style x:Key="HyperlinkButtonStyle2" TargetType="HyperlinkButton">
    <!--Setter Property="TargetName" Value="_new"/-->
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Foreground" Value="Blue"/>
        <Setter Property="Padding" Value="0"/>          
    </Style>

Now I have a style with no control template. Then I select that style in Styles.xaml and do Edit Template > Edit a copy and it adds a linked ControlTemplate to the style:

<Style x:Key="HyperlinkButtonStyle2" TargetType="HyperlinkButton">
    <!--Setter Property="TargetName" Value="_new"/-->
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Foreground" Value="Blue"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template" Value="{StaticResource HyperlinkButtonControlTemplate2}"/>

    </Style>

BUT The documentation for Blend 4 says that it will be created within a style, but it isn't. I absolutely see this as more flexible, but its not what I want becuase I don't want to reuse it and I'm wondering if this is configurable or I'm missing something .

SO: Can I make Blend 4 create a Style and nested ControlTemplate at the same time or do I have to manually move the ControlTemplate into the Style?

+1  A: 

It all depends in which mode you are.

If you follow a specific order of style and template creation, template does get embedded in a style. For example, create a button and do Object > Edit Style > Create Empty ( or Edit Current if you have already attached style to a button). You are in style editing mode. Now, while in style editing mode, select Object > Edit Template and create empty or copy template. It will be linked to style. This is 2 step process that you are following.

However, if you are not in style editing mode, selecting Object > Edit template > Copy creates style with linked template right away.

Tony
I'm looking around at all the 3 different places where you can create a style. It seems that a BUTTON will behave as I described, and a TEXTBOX works as you described. i.e. I cannot whatever I do get a regular BUTTON to create a style+template in a single step. i'm wondering if this is a bug since it doesn't seem to make much sense. hoping you're curious enough to try this yourself :-)
Simon_Weaver
I can confirm you that for a Button I have the described behavior, style and template created in a single step. In fact, I never did tests on TextBox.I am using released version ob Blend, not RC - maybe that has to do with it?
Tony