Currently when i click on a button on my vb.net form that has a color (or a picture) associated with it, it does the action of whatever it's suppose to do
But then,
it starts flashing ... ?
Is it possible to make it not flash after you click it?
edit: This is the XAML of the button
<Button Content="↑ Import" Height="57" HorizontalAlignment="Left" Margin="485,87,0,0" Name="ButtonImport" VerticalAlignment="Top" Width="126" Grid.Column="1" Background="Lime" />
If you set Focus() on something else at the bottom of the event handler for the Button it will stop the button's background from flashing.
For Example:
Private Sub ButtonRefresh_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles ButtonRefresh.Click
refresh()
ListViewOrderDetail.Focus()
End Sub
Related
I have an Event Handler for a keyDownEvent in a TextBox. Now when I press Enter this Event Handler changes the Visibility to Collapsed and the TextBox hides. the Problem with it is that this obviously unfocus the TextBox and foucus sth. else in my App. How can I disable this autofocus of another element and focus nothing?
I have tried the following but i am really screwed.
if (e->Key == Windows::System::VirtualKey::Enter) {
this->mode = ITEM_MODE::SELECT; // will Change Visibility to Collapsed
FocusManager::TryMoveFocus(FocusNavigationDirection::None);
e->Handled = true;
}
Thanks for your help! <3
how to disable auto tab after pressing enter and losing focus of textbox
Derive from official document,
UseSystemFocusVisuals used to get or set a value that indicates whether the control uses focus visuals that are drawn by the system or those defined in the control template.
You could set control UseSystemFocusVisuals property as False. Then next control will not be focused by system.
<StackPanel Orientation="Vertical" Name="RootLayout" IsTapEnabled="False" >
<TextBox HorizontalAlignment="Stretch" Height="44" KeyDown="TextBox_KeyDown" />
<Button Content="FouceElement" UseSystemFocusVisuals="False"/>
<Button Content="NextBtn" UseSystemFocusVisuals="False"/>
</StackPanel>
In case you just don't want the auto-focused item to have focus indicator shown, you can change the Focus type to FocusState.Pointer.
Example (C#):
object focusedElement = FocusManager.GetFocusedElement();
((Control)focusedElement).Focus(FocusState.Pointer); // This will hide focus indicator
I have a data grid which uses a Data Pager to split the data grid up into pages.
I have a button which opens a child window (for editing the data in the grid)
The problem occurs if i navigate to any other page other than 1 - then click the button to edit (which opens the child window), upon closing the child window my Data Pager jumps back to page 1. I would like it to retain the same page that i was viewing after the child window is closed.
Data Pager:
<sdk:DataPager Grid.Row="2" VerticalAlignment="Bottom" x:Name="pager" DisplayMode="FirstLastPreviousNextNumeric" PageSize="30" NumericButtonCount="4" Source="{Binding Path=ItemsSource,ElementName=MyGrid}" />
Child window closing method:
Private Sub BtnCancelClick(sender As System.Object, e As RoutedEventArgs) Handles btnCancel.Click
Close()
End Sub
As you can see, I'm not doing anything other than the default Close() method when i click my cancel button. Is this a built in problem, is there a way to override this?
I have a Windows Store XAML app with a "Save" button, which points to an ICommand property in my ViewModel.
<Button Content="Save"
Command="{Binding DataContext.SaveNewNote, ElementName=grid, Mode=OneWay}"
CommandParameter="{Binding DataContext.CurrentItem, ElementName=grid}" />
on the propertychanged event of my Note model, that fires the CanExecutedChanged event - every time (every keystroke). However, this button will only enable/disable once I leave focus of one of the related textboxes.
In other words, there is a "Name" textbox. If String.IsNullOrWhiteSpace(Name.Text), then CanExecute is set to false. This seems to execute with every keystroke.
I would expect to see this bound Save button enable and disable with each keystroke. HOWEVER, instead, I see the button enable/disable only when I tab out of the textbox.
How can I get this bound button to respect the CanExecuteChanged event on every keystroke, instead of when the texbox loses focus?
The comments by #will and #patrick on the original post both had the correct answer. To do this, you must set the "UpdateSourceTrigger" to "PropertyChanged" and that gives the intended results.
<TextBox Grid.Row="1" PlaceholderText="Enter a short description here"
Text="{Binding NoteAbstract, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
</TextBox>
Sorry for the basic questions, but I've been searching the web for a number of days and can't find the answer to these questions.
I've created a Custom Control, and I will be placing a large number of instances of that Custom Control on my xaml page. In working with that Custom Control in the VB Code Behind, how do I do the following?
How do I reference the name of the Custom Control (in my VB code) which was clicked with the MouseLeftButtonDown event? For example, if I have 10 instances of my Custom Control in xaml, each with a different x:name (say 1-10), when a particular instance is clicked, how can I see which one was clicked? I've tried a number of things including e.OriginalSource.Name (which returns the component within the control which was clicked and not the name of the instance of the control).
My Custom Control consists of numerous parts and pieces (Rectangles, Lines, Text, etc). Each of these items is a part of my layer. In VB code, once I can reference a particular Control, how can I hide or change certain parts of that control (such as hiding a Line, and changing the text). Also, I need to modify more than just the control which was clicked, so I need to be able to access properties of all of the controls, not just what was clicked. For example, if I click Control instance Test1, I also need to modify Test2, Test3, and Test5 in some way.
Here is some test code I through together as part of a Silverlight project using MS Blend 2. My control is much larger, and I need 200 - 250 instances/copies of that custom control, so I really need to know which control instance/copy was clicked.
My UserControl:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MyControl1"
x:Name="UserControl"
d:DesignWidth="60" d:DesignHeight="59">
<Grid x:Name="LayoutRoot" MouseLeftButtonDown="OnMouseClick">
<Rectangle x:Name="Rectangle1" Fill="#FFFFFFFF" Stroke="#FF000000"/>
<TextBox Background="{x:Null}" x:Name="TextBox1" Text="Test" TextWrapping="Wrap"/>
<Ellipse x:Name="Circle1" Fill="{x:Null}" Stroke="#FF000000"/>
<Path Margin="1,29,0,29" x:Name="Line1" Fill="{x:Null}" Stretch="Fill" Stroke="#FF000000" Data="M74,80 L132,80"/>
<Path Margin="0,0,1,14" x:Name="Line2" VerticalAlignment="Bottom" Height="1" Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF000000" Data="M73,95 L131,95"/>
<Path Margin="0,0,0,4" x:Name="Line3" VerticalAlignment="Bottom" Height="1" Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF000000" Data="M73,105 L132,105"/>
</Grid>
</UserControl>
My xaml App using the Custom Control:
<Grid x:Name="LayoutRoot">
<Tester:MyControl1 HorizontalAlignment="Left" Margin="56,54,0,0" VerticalAlignment="Top" Width="60" Height="60" x:Name="Test1"/>
<Tester:MyControl1 HorizontalAlignment="Left" Margin="116,54,0,0" VerticalAlignment="Top" Width="60" Height="60" x:Name="Test2"/>
<Tester:MyControl1 HorizontalAlignment="Left" Margin="176,54,0,0" VerticalAlignment="Top" Width="60" Height="60" x:Name="Test3"/>
<Tester:MyControl1 HorizontalAlignment="Left" Margin="236,54,0,0" VerticalAlignment="Top" Width="60" Height="60" x:Name="Test4"/>
<Tester:MyControl1 HorizontalAlignment="Left" Margin="296,54,0,0" VerticalAlignment="Top" Width="60" Height="60" x:Name="Test5"/>
</Grid>
My Custom Control VB Code:
Partial Public Class MyControl1
Public Sub New()
MyBase.New()
Me.InitializeComponent()
' Insert code required on object creation below this point.
End Sub
Private Sub OnMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim int_Temp As Integer
Dim str_InstanceName As String
str_InstanceName = "1.What code here tells me the name of the instance which was checked? Test1, Test2, etc. for example."
int_Temp = MessageBox.Show(str_InstanceName, "Testing", MessageBoxButton.OK)
'2.What code here lets me manipulate parts of my control instances (and not just the instance which was clicked)?
'I want to hide Test1.Line1 and Test2.Line3 and Test3.Circle1 and change the background of Test5.Rectangle1 for example.
End Sub
End Class
Thanks in advance, and sorry to all the C# experts that I need this in VB.
It looks like you're talking about a User Control, not a Custom Control. There is a little bit of a difference when working with the two. You can read more about those differences here:
Custom Controls Vs. User Controls
In this case, you want to be looking at the 'sender' object in your event handler. You want to cast the sender as your User Control (this will be safe since you're only using that event handler on controls of your type).
Private Sub OnMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim senderAsControl As MyControl1 = sender As MyControl1
' Get the instance name from the sender
Dim instanceName As String = senderAsControl.Name
' You can also access your children from the sender once cast
senderAsControl.Rectangel1.IsVisible = False ' Hide the rectangle
End Sub
I can't compile the code to double check myself at the moment...but it should give you the idea.
I have a silverlight page with a textblock and button on it. Like this:
<TextBlock x:Name="txbNote" Margin="50,50" Text="Hello"/>
<Button x:Name="btnCheck" Height="40" Click="btnCheck_Click" ClickMode="Press" Margin="50,50,50,50" Content="Check Service"/>
Here is the handler for the click event:
Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As EventArgs) 'Handles btnCheck.Click
txbNote.Text = "I Was Clicked"
End Sub
It works... but...
Why doesn't this work?
<Button x:Name="btnCheck" Height="40" Click="btnCheck_Click" ClickMode="Press" Margin="50,50,50,50" Content="Check Service"/>
<TextBlock x:Name="txbNote" Margin="50,50" Text="Hello"/>
The only change is the relative position of the textblock and button. The button's click event (and every other event I tried) just doesn't fire unless the textblock is before the button in the xaml.
You may need to post more code as this could be an issue with the surrounding tags, such as the container that these controls are in.
If you're unable to paste it all to StackOverflow, use www.dpaste.com or www.pastebin.com.
If you place these elements in the Panel instead of the Grid, it starts working.
As you mentioned grid, if you placed two items in grid, the last item is on the top in hierarchy, all top level events are received by TextBlock, you should create two columns in grid and put items in individual columns.