I have a texbox. I would like to show a tooltip when a user brings a mouse on the Textbox.
I write such code, but my program just breaks and VS 2010 gives a window of report.
This is my xaml-code:
<TextBox Height="21" HorizontalAlignment="Left" Margin="231,17,0,0"
Name="Student_textBox" VerticalAlignment="Top" Width="123"
GotFocus="Student_textBox_GotFocus" LostFocus="Student_textBox_LostFocus"
TabIndex="1"
KeyDown="Student_textBox_KeyDown" ToolTip="Hello, Student!"/>
Why does not a tooltip work in WPF 2010?
How to resolve it?
There is nothing wrong with that piece of XAML. Maybe the problem is in one of the event handlers instead (Student_textBox_GotFocus/Student_textBox_LostFocus/Student_textBox_KeyDown)?
What does the error report say? Can you post the error message and possibly a stack trace?
Related
I have a TextBox which I would like to have the focus when the 'view' loads. When I say focus, I mean that the user can start typing straight away and text appears in the focused TextBox.
I've seen so many questions similar here on SO, and they pretty much all have the same answer which is use Dependency Property: FocusManager.FocusedElement
The issue I have is, whilst this does select the control, it doesn't allow the user to type! Normally when you select a TextBlock you get a blinking caret. Using the following, I see a non-blinking caret and I cannot enter text without selecting the textbox (which defeats the point)
<TextBox Margin="10"
Text="{Binding Threshold,
UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True }"
FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"/>
Try moving the declaration to the MainContainer in your XAML
<Grid x:Name="MainContainer"
FocusManager.FocusedElement="{Binding ElementName=txtbox}"
...
>
...
<TextBox Grid.Row="..." Grid.Column="..."
x:Name="txtbox">
</TextBox>
...
</Grid>
I am using Prism 5 and I show a modal dialog via NotificationRequest. I want the focus set in the OK button, so the user can just press Enter to skip de message (now it works with Tab -> Tab -> Enter). I have tried many ways, but no one is working:
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding NotificationRequest, Mode=OneWay}">
<prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.OKButton}"/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
Of course the dialog is showing and there are no errors. The only trouble is the focus in the button.
How can I get this behaviour? What I want is the user press the enter key and the PopupWindow closes as if the button were clicked.
Good catch! Please submit this as an issue here: https://github.com/PrismLibrary/Prism/issues
We will get this fixed with the next update.
Until then, you would have to use a custom window dialog. Check out this sample to learn how to do that.
https://github.com/PrismLibrary/Prism-Samples-Wpf/tree/master/InteractivityQuickstart
Check out the custom popup view: https://github.com/PrismLibrary/Prism-Samples-Wpf/blob/master/InteractivityQuickstart/InteractivityQuickstart/Views/CustomPopupView.xaml
Windows 8
Visual Studio 2012 Express
Simple XAML:
<telerik:RadDataGrid ItemsSource="{Binding ProductsSource}" AutoGenerateColumns="False">
<telerik:RadDataGrid.Columns>
<telerik:DataGridTemplateColumn Header="Whatever">
<telerik:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<ComboBox>
<ComboBoxItem>one</ComboBoxItem>
<ComboBoxItem>two</ComboBoxItem>
<ComboBoxItem>three</ComboBoxItem>
</ComboBox>
</DataTemplate>
</telerik:DataGridTemplateColumn.CellContentTemplate>
</telerik:DataGridTemplateColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>
The binding source is there just to populate the grid with something. In the real app I do use it.
The problem: whenever I select an item from the combobox it does not remain selected, the items appear(dropdown), selection works, but the combobox displays nothing. An out of the grid combobox works ok.
I am new at this and I am definetely missing something.
Yes, this is due to the fact that the ComboBox does not update its VisualState right after the SelectionChanged event is raised, because there is an animation in between.
Best regards,
Ivaylo
I'm simply trying to add a right click context menu for cut/copy/paste to a datagrid so you can right-click on each cell.
I got the menu showing up fine, the trouble is trying to execute the command correctly
<DataTemplate x:Key="BasicTitleEditCellTemplate">
<local:DataContextPropagationGrid>
<TextBox Text="{Binding Path=Person.Name, Mode=TwoWay}" Background="White" />
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Cut" Click="Test_Method" />
<toolkit:MenuItem Header="Copy" />
<toolkit:Separator/>
<toolkit:MenuItem Header="Paste"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</local:DataContextPropagationGrid>
</DataTemplate>
Now the problem I'm having a hard time figuring out, is when the user clicks one of the context menu items, How do I get the text from the textbox they're clicking on? Or the selected text of it rather?
In WPF it always seemed like there were ways you could get the control that the context menu is bound to, I can't figure out anyway in Silverlight to get a reference to that textbox.
How is this commonly done?
You have not provided enough information like are you using MVVM or what?
But it looks pretty simple
<toolkit:MenuItem Header="Cut" CommandParameter="{Binding YourItem}" Command="{Binding YourClickCommand}"/>
My XAML file contains a RadioButton. In the Visual Studio's XAML Designer I can see the display of the Content string for this RadioButton. However, when I run the application, the RadioButton is displayed in the GUI without the Content string "Disble E-mail Alerts from Dashboard". Following is the line in the XAML file which declares the RadioButton:
<RadioButton Height="16" Margin="30,50,0,0" VerticalAlignment="Top" Name="DashboardDisableAlerts" HorizontalAlignment="Left" Width="194">Disble E-mail Alerts from Dashboard</RadioButton>
I will really appreciate any help in helping debug why the Content string is not being displayed in the GUI at runtime.
Thanks
Use a tool like Snoop to examine your visual tree. I suspect the text is there but its foreground color makes it invisible.