Reputation: 2640
How can I reference and change the settings for the ScrollViewer of a WebBrowser component of a C#/WPF/XAML form from the backing C# code?
<WebBrowser ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Name="BrowserForm" />
For example, the following isn't defined:
this.BrowserForm.ScrollViewer.HorizontalScrollBarVisibility
I tried accessing the ScrollViewer from the VisualTreeHelper, but the following returns 0:
VisualTreeHelper.GetChild(this.BrowserForm, 0)
Upvotes: 1
Views: 1240
Reputation: 61349
That syntax doesn't work because you are setting an attached property (MSDN).
To set it in code, you have to utilize the static method defined by the class defining the property, in this case ScrollViewer.SetHorizontalScrollBarVisibility
ScrollViewer.SetHorizontalScrollBarVisibility(MyBrowser, ScrollBarVisibility.Visible);
Note: WebBrowser
does not appear to actually be affected by this property, in XAML or in code, but this concept is correct. You may want to try wrapping your WebBrowser
inside of a ScrollViewer
if you want more control over scrolling.
Upvotes: 2