Yes, you need data binding to the converter, for example, the following example
xmlns:conv="clr-namespace:MyConverters.Converters" ....... <UserControl.Resources> <conv:WidthConvertercs x:Key="widthConv"></conv:WidthConvertercs> </UserControl.Resources> <Border Name="switchCase" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <Border Name="slider" Width="{Binding ElementName=switchCase, Path=ActualWidth, Converter={StaticResource widthConv}}" Background="DarkMagenta"></Border> </Border>
Your converter class will be
[ValueConversion(typeof(double), typeof(double))] class WidthConvertercs : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double withPar = (double)value; return withPar/2.0; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
I hope this helps
source share