Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic Tooltip WPF

Posted on 2009-04-15
4
Medium Priority
?
1,530 Views
Last Modified: 2013-11-12
Firstly; I am very very new to WPF - so please excuse me if this sounds ridiculous.
I need to have dynamic tool tips in my application. The data in the tooltips can change so I can't just hard code them; the contents of the tooltips will probably be stored in a database (or a wiki)
Is there a way in WPF that I can perhaps bind my tooltip to an underlying business class that can go away and return the correct tool tip?

Any help would be very much appreciated
Thanks in advance
0
Comment
Question by:Steven_Prescott
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
unmeshdave earned 2000 total points
ID: 24150128
<ToolTip x:Key=toolTipTextBoxBinding
         DataContext={Binding Path=yourclassobectproperty,
           RelativeSource={Staticresource yourclassobject}}>
your class property should change dynamically the way you want.
 


0
 

Author Comment

by:Steven_Prescott
ID: 24155292
There are a number of errors coming up when I attempt the above example... I am not sure if this is due to a schema that I am using? or just how I am attempting to bind the tooltip..
I have attached the xaml code and the basic outline of the underlying class that I want to attach to.
I want the tooltip for the name to show the current name and likewise for the age

Any help on this would be very much appreciated
Thanks in advance
This is the xaml file...
<Window x:Class="WpfApplication1.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="110" Width="270">
 
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="200" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="Name:" />
        <Label Grid.Row="1" Grid.Column="0" Content="Age:" />
 
        <TextBox Grid.Row="0" Grid.Column="1" Margin="3" Name="txtName" />
        <TextBox Grid.Row="1" Grid.Column="1" Margin="3" Name="txtAge" />
        <Button Grid.Row="2" Grid.Column="1" Name="incrementAgeButton" Click="incrementAge_Click">Increment Age</Button>
    </Grid>
</Window>
 
and this is the shape of the class
public class Person
{
   public string Name
   public int Age
}

Open in new window

0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24160031
If you want to bind Name and age to the relevant textbox tooltip, you need to declare them as properties. also please show how you put tooltip code, and what errors you are getting.
0
 

Author Closing Comment

by:Steven_Prescott
ID: 31570545
I had not put a datacontext in the "parent" grid
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question