Используйте Binding
и Converter
.
public sealed class VisibilityToBorderThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
var flag = (Visibility)value;
if (flag == Visibility.Visible)
return new Thickness(0);
else
return new Thickness(1);
}
catch
{
return new Thickness(0);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
и чем ваш xaml:
<ScrollViewer Name="blah">
<Border BorderThickness="{Binding ElementName=blah, Path=VerticalScrollBarVisibility , Converter={StaticResources VisibilityToBorder}}">
</ScrollViewer>
не забудьте добавить свой конвертер в ресурсы!
GL & HF