1

I have written this code:

<ControlTemplate TargetType="Label">
                <Grid Height="30" Width="70" x:Name="grid">
                    <Border>
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"></ContentPresenter>
                    </Border>
                    <Separator>
                        <Separator.Margin>
                            <Thickness Left="{Binding Path=Width,RelativeSource={RelativeSource AncestorType=Label}}" Top="0" Right="0" Bottom="0"/>
                        </Separator.Margin>
                        <Separator.LayoutTransform>
                            <RotateTransform Angle='120'/>
                        </Separator.LayoutTransform>
                    </Separator>
                </Grid>
            </ControlTemplate>

I want to bind only left margin of separator, but this code gives me error. Any other solution?

Ravi
  • 960
  • 1
  • 18
  • 41

1 Answers1

2

A Binding can only be applied to a DependencyProperty: What is a dependency property?

Thickness.Left isn't a dependency property, so you'll have to bind the whole Margin (which is a dependency property). To adjust only the left edge, you could create a ValueConverter that takes the Width and returns a Thickness. Example:

<Separator Margin="{Binding RelativeSource={RelativeSource AncestorType=Label},
                            Path=Width,
                            Converter={StaticResource MyLeftMarginConverter}}" >
    <Separator.LayoutTransform>
        ...
Community
  • 1
  • 1
Sphinxxx
  • 12,484
  • 4
  • 54
  • 84