Ok, so I'm trying to figure out how to set a status bars label text to show information about the current control that a mouse is hovering over. I have seen this numerous times on many programs so I know it can be done and I'm sure there are explanations out there that could help me but I can't seem to find the right words to search for the answer unfortunately... The closest thing I could find was in the link below. I tried to utilize this but it gave me an error when I tried to set the text property.
Anyone have some information or a link to help me by chance? Thanks, Ryan
Display text in a label when hovering over a control without using events
My XAML Code:
<StatusBar>
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="75" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<Label Content="New Lead Inquiry" />
</StatusBarItem>
<Separator Grid.Column="1" Style="{StaticResource StylingStatusBarSeparator}" />
<StatusBarItem Grid.Column="2">
<Label x:Name="infoStatusBar" Content="Label for text about the currently hovered item" />
</StatusBarItem>
<Separator Grid.Column="3" Style="{StaticResource StylingStatusBarSeparator}" />
<StatusBarItem Grid.Column="4">
<Label Content="Not Saved" />
</StatusBarItem>
</StatusBar>
You can wire the
MouseEnter
andMouseLeave
commands on your controls to set aHelpText
property in your viewmodel, and then bind the status bar label toHelpText
so that when it is set to something new, the new value appears in the status bar.This answer uses the MVVM Light toolkit, but should be adaptable for any MVVM setup:
In XAML:
In your viewmodel:
First, add properties for your HelpText and your ICommands:
Then initialize your ICommands in your viewmodel constructor to point at methods in the viewmodel:
Then create your helper methods to set the HelpText property:
This is the running sample shown with the mouse hovered over
Label2
:Here's a solution that doesn't require you to modify each child control or use any frameworks.
This isn't really related to MVVM, since it's pure UI stuff. There's nothing here that would involve a viewmodel.
Handle Window.PreviewMouseMove:
MainWindow.xaml
MainWindow.xaml.cs
Define a dependency property of type Object, and in the preview mousemove handler, give it the nearest parent tooltip of the control the mouse is over:
And bind that to whatever in the XAML.
That Label is just the quickie I put in my test XAML. This binding is the important part there:
If you're willing to settle for fewer style points, you can do it without the dependency property or the binding:
MainWindow.xaml
MainWindow.xaml.cs