WPF TextBox repaints multiple times with mouse hover - wpf-controls

I am using Windows Performance suite (which part of Microsoft Windows SDK) to profile my sample application. I am using the "Perforator" with an option "Show dirty-region update overlay", which enables me to see when and where areas are redrawn in an application.
When I hover mouse over a TextBox control then I see that it is redrawn multiple times and the CPU utilization goes up. I tested with a very simple window with just a TextBox control and a button control.
Is this normal for WPF to redraw control on mouse hover?
Is there anything that I can do to minimize this?
Here is the windows that I am using
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBox Height="25" Width="150" >
</TextBox>
<Button Margin="10,0,0,0" Height="25">1211</Button>
</StackPanel>
</Grid>

Its not "normal" for WPF to redraw the control on mouse over, because WPF only updates the region that has changed (using retained mode graphics):
One of the biggest benefits in using retained mode graphics is that
WPF can efficiently optimize what needs to be redrawn in the
application. Even if you have a complex scene with varying levels of
opacity, you generally do not need to write special-purpose code to
optimize redrawing (see Intelligent Redrawing in the Retained Mode Graphics section).
The problem in this case is that the active Windows theme is applied to the controls. When you move the mouse over the button, you'll see that the button slightly changes to a "light blue-transparent" color (though this depends upon your active Windows theme). At the same time, once you focus the button, another "animative" type of behavior is applied to the button. You can clearly see this with the dirty-region checked.
If you want to change this, you need to define your own theme, overriding the default-theme-behavior. Here's a post to get you started.

Related

Xcode 10 - how to pin UI element library window?

I'm laying out UI on a storyboard using the new, controversial library button which has been moved up.
This is driving me crazy - I want to be able to "PIN" this window to a secondary monitor so I can always see available components as opposing to having to click that button every single time I need an element. Currently it disappears, even on secondary monitor once I shift focus to the view controller on screen.
How do I pin the UI Elements library to be able to always see it ?
You can press the option button in keyboard and click in the library window, it's will hold
Picture of library windown

How do I find the control to test against with CodedUI in VS 2015?

I'm using VS 2015 Enterprise. I'm new to CodedUI testing. I've added a CodedUI test project to my solution. I've created a simple test, clicked on a button, selected a radio button, etc.
I've been following a Pluralsight course titled "Test Automation with CodedUI". I want to find a control on the WPF form, but once I select the control finder in the test builder and move the mouse off to the running application, it is no longer a bulls eye. I don't understand why its different than what's shown in the Pluralsight course. I think the instructor used VS 2012. Could that be the reason?
There are subtle changes between versions. After clicking the assertion builder button in the Coded UI recorder then, as you move the mouse pointer around the screen (do not move it too fast or you will confuse yourself), you should see a blue rectangle drawn around parts of the screen. As you move the mouse pointer carefully you should be able to select larger or smaller sections, corresponding to higher or lower items within the hierarchy of controls on the screen. Click on a control of interest. You should then see a window showing the properties of the selected control. There are four arrows (up, down, left and right) in the new window. Click on these to navigate around the control hierarchy. Note that and 'up' followed by a 'down' will seldom return to the same control. The 'up' moves the parent control and the 'down' moves to the first child.
My suggestion here would be to use the keyboard shortcut to enable the control finder. When you hover over it with your mouse you should see it - if I recall correctly it's "Alt + H". Basically you'll move your mouse to the control you want to identify, then do the keyboard shortcut, then click. It should identify the control correctly at that point.

How to properly display a focus rectangle in a compact SplitView menu item

I'm building my first Universal Windows Platform (UWP) App and am trying to implement the popular "Hamburger Menu" using the SplitView class.
Inspired by many samples, the items hosted on the SplitView pane are re-styled RadioButton controls, with a vertical highlight-rectangle, an icon and a text. The appearance is similar to that of the Groove app.
I'm now trying to implement navigation and selection using the keyboard, and this now bring a little focus-rect around the items in the SplitView pane. However, since the pane clips its contents when its DisplayMode is either CompactInline or CompactOverlay, the focus rectangle is also clipped, which is not the behavior a user would expect.
Please, can anyone advise on how to property display the focus rectangle in this situation ?
Just an idea, what if you set the width of all radio button's to be same as the CompactPaneLength property of SplitView. The default is 48 DIPs.

Draggable TextBox in WPF

Is there any way to create a draggable textbox in WPF ? I can see lot of ways of creating draggable TextBlock in WPF. But can't find a similar way to achieve this for Textbox.
Normally a drag is started if the mouse is moved a few pixels while at least one mouse button is down. This "pattern" also appears when selecting text in a textbox. It seems there will be no way to tell this actions apart, so this might be the reason there is no "movable textbox" designed this way.
As a possible way to solve your problem you could take this approach into account: Universally usable editable label
Alternatively you could add some area to your textbox, which reacts to moving.
<StackPanel Orientation="Horizontal">
<Rectangle x:Name="DraggablePart" .../>
<TextBox .../>
</StackPanel>
Or even some kind of adorner, which will appear only, when the textbox is hovered.

Holding an item steady against scrolling in scroll viewer in windows store app

I want to hold a section label stable at the top of a ScrollViewer in a windows store app, while that section has not scrolled off. For example, the windows weather app does this with the section labels in the top left as you scroll to the right.
Currently the control I want to hold stable is nested inside a ScrollViewer control. I have an intermediate solution that holds it mostly steady by updating the control's render offset in response to the ViewChanged event. However, there's still some very obvious stuttering as I scroll. I've also considered "pretending" the control is in the scroll viewer, when it is actually outside of it, but this would break a lot of encapsulation.
How do I hold a section label perfectly still as the control it is logically inside of is scrolled over?
If you put the ScrollViewer and your Label into a Grid you can keep the label in the same position:
<Grid>
<Label/>
<ScrollViewer>...</ScrollViewer>
</Grid>

Resources