Accessing the ScrollViewer of a ListBox from C#

前端 未结 6 1671
醉酒成梦
醉酒成梦 2020-12-01 18:26

I\'d like to change the properties of a ScrollViewer of a ListBox from C#.

I found this question here on Stackoverflow. I took the accepted

6条回答
  •  借酒劲吻你
    2020-12-01 18:52

    The properties of the ScrollViewer are "attached" to the ListBox (cf. https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview). You can get or set it as for a dependency property by the functions:

    public object GetValue (System.Windows.DependencyProperty dp);

    and

    public void SetValue (System.Windows.DependencyProperty dp, object value);

    For example, for the listbox 'lb', you can write:

    lb.GetValue(ScrollViewer.ActualHeightProperty); or lb.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);

提交回复
热议问题