AutoSuggestBox restores Text after pressing Escape - win-universal-app

I'm using an AutoSuggestBox to perform Search. It works as expected except when I set the Text property programmatically.
As an example, let's assume the following xaml:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<AutoSuggestBox x:Name="SearchBox" />
<Button Content="Clear" Click="ButtonBase_OnClick"/>
</StackPanel>
</Grid>
On the Click event handler, I've put:
SearchBox.Text = string.Empty;
SearchBox.Focus(FocusState.Programmatic);
As you can see, the goal here is to Clear the AutoSuggestBox text. After I click on the button the Text is cleared but, if I press Escape, the previous Text is restored.
Is there any way to override this escape behaviour?
Thanks.
DMVC

Related

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.

Prevent the listview from scrolling to its top position when ItemSource changed Windows 8.1

So is there a way to stop scrolling up ?
I have listview's scrollview and i tryed saving last position and in listview size changed scroll down - but it first scrolls down and later up ;/ Maybe there is some different event or completly different way ?
You can set the ItemsStackPanel's ItemUpdatingScrollMode.
<ListView>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel ItemsUpdatingScrollMode="KeepScrollOffset" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
It only works when the scroll offset is greater than 0, so just scroll using ChangeView() to set it up.

WPF Popup doesn't close even if I open new screen from menu

I have a WPf popup inside Usercontrol which I open & closed by binding IsOpen property. Problem which I am facing is that popup doesn't close even if I open a new screen from menu using hotkey and its showing on top of new screen. I tried to set StaysOpen="False" but its not working.
Popup IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center" VerticalAlignment="Center" PopupAnimation="Fade" HorizontalOffset="30" StaysOpen="False">
Thanks,

New line in the text box

I'm the Inter-key in textBox.But the new line will not.What do I need.
Whether there is a solution ?
<TextBox
Name="tbMultiLine"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible"
>
This TextBox will allow the user to enter multiple lines of text. When the RETURN key is pressed,
or when typed text reaches the edge of the text box, a new line is automatically inserted.
</TextBox
See How to: Create a Multiline TextBox Control
Use a Textblock and set the following parameters in your XAML:
<TextBox name="textBox1"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible"
AcceptsReturn="true"/>

WPF TextBox repaints multiple times with mouse hover

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.

Resources