Set style for all textblocks in a stack panel

In the resources section for your main container put your style with a x:Key attribute and a target type of TextBlock. Then in each resources section for each StackPanel you can put a style where the BasedOn attribute is set to the key of your main style (don’t forget to use StaticResource binding, not just the name of the key) and then say TargetType="{x:Type TextBlock}" and end the tag. this should bring the style into the StackPanel and style all of your TextBlocks.

<Window ...>
    <Window.Resources>
        <Style x:Key="tbstyle" TargetType="{x:Type TextBlock}">
            <!-- put setters here -->
        </Style>
    </Window.Resources>
    <StackPanel name="SPA">
        <StackPanel.Resources>
            <Style BasedOn="{StaticResource tbstyle}" TargetType="{x:Type TextBlock}" />
        </StackPanel.Resources>
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
    </Stackpanel>
    <StackPanel name="SPB">
        <StackPanel.Resources>
            <Style BasedOn="{StaticResource tbstyle}" TargetType="{x:Type TextBlock}" />
        </StackPanel.Resources>
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
        <TextBlock ... />
    </StackPanel>
</Window>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)