0

I have Pivot style. Within this Pivot style I have the PivotHeaderItem style. Now I want to bind the foreground value of the PivotHeaderItem to the background value of the Pivot.

  • I have tried to TemplateBinding to outer style but it's not working.
  • I have tried to Binding ElementName Path to outer style but it's not working.

Here is the structure of my code. I have deleted many codes due to character limitation of StackOverflow.

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="OfficeTabPivotStyle" TargetType="Pivot">
        <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAccentBrush}"/>
        ....
        <Setter Property="Template">
             .....
             .....
                <Grid Margin="5,0,0,0" Background="{ThemeResource PivotHeaderBackground}">
                    <Grid.RenderTransform>
                        <CompositeTransform x:Name="HeaderOffsetTranslateTransform"/>
                    </Grid.RenderTransform>

                    <Grid.Resources>
                        <Style TargetType="PivotHeaderItem">
                            <Setter Property="Foreground" Value="{Bind the pivot background value}" />
                            ....
                            ....
                        </Style>
                    </Grid.Resources>
                    ....
                    ....
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
Vijay Nirmal
  • 5,239
  • 4
  • 26
  • 59
  • What about Binding to an Ancestor? I guess something like `{Binding Path=Background, Mode=FindAncestor, RelativeSource={RelativeSource AncestorType={x:Type Pivot}}` can solve your problem. – LittleBit May 08 '18 at 07:20
  • @LittleBit `FindAncestor` is not available in UWP – Vijay Nirmal May 08 '18 at 07:33
  • Not sure I understand. You already have your parent bound to `SystemControlBackgroundAccentBrush` so why not just do the same in the child? – Chris W. May 08 '18 at 20:09
  • @ChrisW. This is not the real scenario. Actually, I want to bind the `background` value of the Pivot to a `Storyboard` `To` property in `PivotHeaderItem` style to change the foreground value of the `PivotHeaderItem` – Vijay Nirmal May 09 '18 at 06:11
  • @XavierXie-MSFT No, I want to link background property of `Pivot` to `PivotHeaderItem`. It's completely different question. Basically, my question is "How to Bind properties of inner Style to its Outer Style?" – Vijay Nirmal May 09 '18 at 08:32

0 Answers0