Создать конвертер значений:
[ValueConversion(typeof(bool), typeof(ScrollBarVisibility))]
sealed class MouseOverToScrollBarVisibility : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((bool)value) ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
Объявите это где-нибудь в ресурсах:
<Window.Resources>
<local:MouseOverToScrollBarVisibility x:Key="MouseOverToScrollBarVisibility" />
</Window.Resources>
И использовать его для привязки ScrollViewer.VerticalScrollBarVisibility
свойства к IsMouseOver
свойство:
<DataGrid ScrollViewer.VerticalScrollBarVisibility=
"{Binding IsMouseOver,
RelativeSource={RelativeSource Self},
Converter={StaticResource MouseOverToScrollBarVisibility}}">
</DataGrid>