简体   繁体   中英

How to call a Style Property setter of another property that is set in in the same style in xaml

I am writing a style in a user control to control the styles of single axes from a collection of axes. This all works but now I want to integrate a rotation of the AxisTitle.
But if I do the following (only title setter is shown):

<UserControl.Resources>
<Style x:Key="AxisStyle" TargetType="myLib:AxisBase">
    <Setter Property="AxisTitle" Value="{Binding Title, Mode=OneWay}" />
    <Setter Property="RenderTransform">
        <Setter.Value>
            <RotateTransform Angle="90" />
        </Setter.Value>
    </Setter>
</Style>
</UserControl.Resources>

Then the rotation is applied to the axisbase which is all of the axis not just the title. (I understand why)
But how can I change the code so that this RenderTransform applies to the AxisTitle?

What works if I do it to a specific instance of axis is the following:

<Resources>
    <Style x:Key="AxisTitleStyle" TargetType="myLib:AxisTitle">
        <Setter Property="RenderTransform">
            <Setter.Value>
                <RotateTransform Angle="90" />
            </Setter.Value>
        </Setter>
    </Style>
</Resources>

<Axis Style="{StaticResource AxisTitleStyle>/>

But I would like to put it to the styling of AxisBase to style the title inside.
Q: Is this possible?

This is only the first step to what I finally want to achieve. A property dependant rotation like this (pseudo code):

<Style.Triggers>
    <DataTrigger Binding="{Binding Path=Axis.RotateTitle}" Value="True">
        <Setter Property="RenderTransform">
            <Setter.Value>
                <RotateTransform Angle="90" />
            </Setter.Value>
        </Setter>
    </DataTrigger>

    <DataTrigger Binding="{Binding Path=Axis.RotateTitle}" Value="False">
    <!-- Do nothing -->
    </DataTrigger>
</Style.Triggers>

But first I have to find out how to set the RenderTransform to the AxisTitle inside the Style.

I would, of course, have to see the Axis visual tree to know for sure what you want, but it sounds like you want to apply the transform to the xaml element that is bound to the axis title inside Axis. Axis, no doubt, is a visual tree that you can take apart with Blend pretty easily (Edit Existing Template).

Once you have the full, existing style template for Axis, you can tweak the bit that actually refers/binds to the title so that a transform can be dynamically applied. Hope that helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM