wpf control width binding wpf control width binding wpf wpf

wpf control width binding


Change the path to ActualWidth.

<Border x:Name="border1" Width="{Binding Path=ActualWidth, ElementName=border2}"></Border><Border x:Name="border2"></Border>


change path to ViewportWidth too !

<Grid x:Name="mainGrid">//and some elements exist there  <Grid>     <Border x:Name="border_btn" Width="{Binding ElementName=root ,Path=ViewportWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>    </Grid></Grid>

use ViewportWidth instead of ActualWidth because in this case ActualWidth is always shown 0! for test this problem you can test this with this line in your xaml.

  <TextBlock Text="{Binding  ElementName=mainGrid, Path=ActualWidth ,Mode=TwoWay}" Foreground="Red"/>