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.
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>
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
I have a map with a MapItemsControl in my WP7 app that contains pushpins bound to items in a collection of custom classes. The pushpins are bound to properties of the item in the collection via a DataTemplate.
When an item is added to or removed from the collection, all pins display correctly, with properties as per bindings, but when just an items’ properties are modified, the UI does not update. The bindings just seem to get values from the source item upon loading, but I'd like them to keep the UI elements updated when the source collection items' properties are updated.
To illustrate, I’ll create a similar example:
Here’s a custom class:
Public Class Box
Property CurrentColor As Color
Property Location As GeoCoordinate
End Class
There's a collection of them:
Dim TempBoxes As ObservableCollection(Of Box)
My map control has a MapItemsControl in it:
<maps:MapItemsControl Name="BoxControl"
ItemTemplate="{StaticResource BoxTemplate}"
ItemsSource="{Binding TempBoxes}"/>
The item template is something like this:
<DataTemplate x:Key="BoxTemplate">
<maps:Pushpin Location="{Binding Location}" ManipulationStarted="BoxTouched">
<maps:Pushpin.Template>
<ControlTemplate>
<Ellipse Width="35" Height="35" Margin="54,148,366,584"
Stretch="Fill" StrokeThickness="4" Stroke="Black"
Fill="{Binding CurrentColor}" />
</ControlTemplate>
</maps:Pushpin.Template>
</maps:Pushpin>
</DataTemplate>
The touch event handler switches the pin's color between blue and red:
Private Sub BoxTouched(ByVal sender As Object, ByVal e As RoutedEventArgs)
With DirectCast(DirectCast(sender, Pushpin).DataContext, Box)
If .CurrentColor = Colors.Red Then
.CurrentColor = Colors.Blue
Else
.CurrentColor = Colors.Red
End If
End With
End Sub
Whenever I add or remove items from TempBoxes, the pins all render as they should (e.g. if I specify a color in the collection item, the pin shows the color).
Tapping on the item triggers the BoxTouched sub, which causes the item's color to change in the collection, but the UI doesn't change (pin color stays the same).
To get the UI to update the color, I have to get it to render the pins again, by adding something like this to BoxTouched:
BoxControl.ItemsSource = Nothing
BoxControl.ItemsSource = TempBoxes
I'm assuming there's a better way to do this?
In order for the DataTemplate to respond to changes in property values for your data object you need to implement the INotifyPropertyChanged interface on your data object so that property change notification is raised when your properties change.
Take a look at the VB samples in the MSDN documentation if you're unsure how to do this.