Silverlight ScrollViewer takes focus when scrollbars are not visible - silverlight

I'm finding that Silverlight's ScrollViewer will still take focus even when the scrollbars are not visible.
Has anyone else seen this issue? Are there any workarounds that will prevent the ScrollViewer acting as a tabstop when the scrollbars are invisible?
Thanks,

What about:
<ScrollViewer IsTabStop="False" ...

There is a simple solution, at least in Silverilght 4 and up. Listen to the LayoutUpdated event on the ScrollViewer and set the IsTabStop property based on the status of the scrollbars.
For example, if you only are using a vertical scroll bar:
void myScrollViewer_LayoutUpdated(object sender, EventArgs e)
{
//this should only be a tabstop if the scrollbar is visible.
myScrollViewer.IsTabStop =
(myScrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible);
}

Related

Custom window drag handler interferes with scrollviewer bar drag

I have a window with window style set to None that handles OnPreviewMouseDown, OnPreviewMouseUp, and OnMouseMove so that the window can be dragged from anywhere.
The windows code behind looks like this:
bool inDrag;
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonDown(e);
inDrag = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (inDrag && e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonUp(e);
if (inDrag)
{
inDrag = false;
}
}
Now problem is I have a large menu in this window that has a scroll bar which works with the scroll wheel and by clicking to a position on the scrollviewer but not when clicking and dragging the scroll bar itself. Also if I click and hold and move my cursor not on top of the window the scrolling works again. This has led me to believe that the above dragging implementation is blocking the scrollviewers drag functionality.
I tried manually raising the event with .RaiseEvent(e) in OnMouseMove but this causes a stack overflow exception when I move my mouse over the window.
How can I get my Scrollviewer to respond to mouse movements without removing my click and drag window behavior?
<!--ScrollViewer subscribed to PreviewMouseDown to set inDrag to false-->
<ScrollViewer Visibility="Visible" Mouse.PreviewMouseDown="ScrollViewer_PreviewMouseDown">
<!--The Grid fill all the available space and is subscribed to PreviewMouseDown event to set inDrag to true-->
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Mouse.PreviewMouseDown="Grid_PreviewMouseDown" Background="Transparent">
<!--My menu-->
</Grid>
</ScrollViewer>
Note that if there is "blank space" (no Background set including that of the Content),
the PreviewMouseDown event won't be raised despite the subscription.
If needed, to work around that you can set the Background of the Grid to Transparent and the event will be raised even on seemingly blank space.

DotNetBrowser inside a ScrollViewer cannot scroll in WPF application

I have a WPF application where I put on several DotNetBrowser.WPF.WPFBrowserView elements inside a ScrollViewer vertically.
My problem is that these are not scrolling when I start scrolling with the ScrollViewer. I know that this is just an embedded separated window (or something like that) but I have to made this able to scroll.
Is there any way to achive this?
Thank you for any help in advance!
You can solve this by handling ScrollChanged event for the ScrollViewer.
Here's quick example:
scrollViewer.ScrollChanged += delegate (object sender, ScrollChangedEventArgs e)
{
browserView.Browser.SetBounds(-(int)e.HorizontalOffset, -(int)e.VerticalOffset, (int)browserView.ActualWidth, (int)browserView.ActualHeight);
};
You can also try to use lightwight mode.
Browser browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT);
var browserView = new WPFBrowserView(browser);

How to hide Grid border

I have a grid with some controls inside. I want to hide the grid border.
Are there any specific properties which can be used to hide the grid border in WPF?
Set DataGrid.BorderThickness to 0.
I know this is a bit late to add to the thread but incase anyone else stumbles on this question this worked for me:
<Grid ShowGridLines="False">
I too had a similar problem of getting dotted border around a part(Grid) of user control, only when focus is being set to the Grid and solved the problem using;
void Grid_GotFocus (object sender, RoutedEventArgs e) {
Grid.FocusVisualStyle = null;
}
Hope it helps someone :)

WPF ListBox Scrolling and Button Visibility

I am replacing the scroll bar for a list view with a "scroll up" and "scroll down" buttons. My question is, is there any way to show the buttons only when the list box can be scrolled?
i.e. My listbox may only have a couple of items...in that case I wouldn't need to show the buttons becuase there is nothing to scroll to.
I'm implmenting this across multiple listboxes and there is no set size of the items/lisboxes. I'm hoping there is some event that I can hook onto like a "scrollviewer_initializeed" or something.
Set the ListBox.ScrollView.VerticalScrollBarVisibility to Hidden and handle the ListBox.ScrollView.ScrollChanged event like this:
<ListBox ScrollViewer.ScrollChanged="ListBox_ScrollChanged"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
And then add this method to handle the ScrollChanged event:
private void ListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
ButtonScrollUp.Visibility = ButtonScrollDown.Visibility =
((ScrollViewer)e.OriginalSource).ScrollableHeight > 0
? Visibility.Visible
: Visibility.Collapsed;
}
This is assuming your buttons are named ButtonScrollUp and ButtonScrollDown.
ScrollViewer.ScrollableHeight will equal the number of items out of view, so if it is greater than 0 your buttons should be visible.
The simplest solution would be to custom style the scrollviewer:
Simply set the Vertical scroll bar's visibility to "Auto", and hide all parts of the control template except for the top and bottom "RepeatButton" parts.
An example of styling the scrollViewer is here, but I'm sure you could find better ones with a quick search.

WPF Ribbon - Hide quick access toolbar

how do you hide Quick Access Toolbar in a WPF's Ribbon?
For Microsoft Ribbon for WPF, you can hide it by using the VisualTreeHelper. On the Loaded event handler, just resize the row containing the Quick Access Toolbar to 0 :
private void RibbonLoaded(object sender, RoutedEventArgs e)
{
Grid child = VisualTreeHelper.GetChild((DependencyObject)sender, 0) as Grid;
if (child != null)
{
child.RowDefinitions[0].Height = new GridLength(0);
}
}
The Quick Access Toolbar is automatically hidden when the Ribbon control is in a RibbonWindow. When it is not, it seems impossible to hide it. I have already worked hours on this issue and was unable to hide it properly.
But there is one simple workaround: Place the Ribbon control inside of a Panel and give it a negative top margin so it will slide outside of the Panel. Set the Panel's ClipToBounds property to true and the QAT will be hidden.
By the way - there are multiple Ribbon implementations for WPF, even by Microsoft themselves ("Fluent Ribbon" and "Microsoft Ribbon for WPF"), so next time you should mention which one you are talking about.
Or if you want it all in the XAML, this works
<ribbon:Ribbon>
<ribbon:Ribbon.Loaded>CollapseQuickAccessToolbar</ribbon:Ribbon.Loaded>
<x:Code>
private void CollapseQuickAccessToolbar(Object sender, RoutedEventArgs e) {
((Grid)VisualTreeHelper.GetChild((DependencyObject)sender, 0)).RowDefinitions[0].Height = new GridLength(0);
}
</x:Code>
</ribbon:Ribbon>
Here is the solution :
this.ribbonControl1.ToolbarLocation = DevExpress.XtraBars.Ribbon.RibbonQuickAccessToolbarLocation.Hidden;
I know this is an old post, but found an easier solution...
Add this inside the ribbon :-
<ribbon:Ribbon.QuickAccessToolBar>
<ribbon:RibbonQuickAccessToolBar Visibility="Collapsed"/>
</ribbon:Ribbon.QuickAccessToolBar>
Bit late to the party.
<my:Ribbon >
<my:Ribbon.ApplicationMenu >
<my:RibbonApplicationMenu Visibility="Collapsed">
</my:RibbonApplicationMenu>
</my:Ribbon.ApplicationMenu>
This will help to hide the quick bar

Resources