473,657 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Templated Combobox Tooltips from Items

Hello,

I have a ComboBox with a style that sets its Template and ItemTemplate. I'd
like to set the tooltip of the combo to the tooltip of the currently selected
item, but I am having trouble doing so.

I've used Marco Zhou's solution in the thread
http://social.msdn.microsoft.com/For...-0243162266ef/ as a starting point, but have not had any success yet.

Thanks,
WtS
Oct 3 '08 #1
3 4794
Hi Wts,

You can use a converter to display the tooltip of the current selected item
on the tooltip of the ComboBox. I write the following sample based on
Macro Zhou's for your information.

[C# Code]

namespace WpfApplication4
{
public partial class Window1 : Window
{
public Window1()
{
InitializeCompo nent();
}
}

[ValueConversion (typeof(object) , typeof(String))]
public class MyToolTipConver ter : IValueConverter
{
public object Convert(object value, Type targetType, object
parameter, CultureInfo culture)
{
ComboBoxItem selectedItem = (ComboBoxItem)v alue;
//Return the tooltip of the current selected item;
return selectedItem.To olTip;
}

public object ConvertBack(obj ect value, Type targetType, object
parameter, CultureInfo culture)
{
return value;
}
}
}
[XAML code]

<Window x:Class="WpfApp lication4.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
xmlns:local="cl r-namespace:WpfAp plication4"
Title="Window1" Height="300" Width="300">

<Window.Resourc es>
<local:MyToolTi pConverter x:Key="myToolti pConverter"/>
</Window.Resource s>

<DockPanel>

<ComboBox x:Name="combo" SelectedIndex=" 0" DockPanel.Dock= "Top"
Height="23" Width="251">
<ComboBoxItem ToolTip="FirstI tem">one</ComboBoxItem>
<ComboBoxItem ToolTip="Second Item">two</ComboBoxItem>
<ComboBoxItem ToolTip="ThirdI tem">three</ComboBoxItem>
<ComboBox.ToolT ip>
<ToolTip DataContext="{B inding Path=PlacementT arget,
RelativeSource= {RelativeSource Self}}">
<TextBlock Text="{Binding Path=SelectedIt em,
Converter={Stat icResource myTooltipConver ter}}" Foreground="Gre en"/>
</ToolTip>
</ComboBox.ToolTi p>
</ComboBox>
</DockPanel>

</Window>
If any part of the sample code is unclear, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 6 '08 #2
Hi Zhi-Xin,

Thanks, but what I'd really like (if possible) is a way to get the tooltip
of the selected item within a ControlTemplate , without having to write a
converter for each use of this style.

I have something like this (parts snipped for brevity):
<ControlTemplat e x:Key="pulldown Template" TargetType="{x: Type ComboBox}">
<Border Style="{Dynamic Resource NormalButtonBor der}">
<Grid>
<ToggleButton Name="ToggleBut ton" />
<ContentPresent er
Name="ContentSi te"
IsHitTestVisibl e="False"
Content="{Templ ateBinding SelectionBoxIte m}"
ContentTemplate ="{TemplateBind ing
SelectionBoxIte mTemplate}"
ContentTemplate Selector="{Temp lateBinding
ItemTemplateSel ector}"
Margin="3"
VerticalAlignme nt="{TemplateBi nding
VerticalContent Alignment}"
HorizontalAlign ment="{Template Binding
HorizontalConte ntAlignment}">
<ContentPresent er.ToolTip>
<!-- I would assume something goes here -->
</ContentPresente r.ToolTip>
</ContentPresente r>
<Popup Name="Popup" />
</Grid>
</Border>
</ControlTemplate >
Thanks,
Wts

"Zhi-Xin Ye [MSFT]" wrote:
Hi Wts,

You can use a converter to display the tooltip of the current selected item
on the tooltip of the ComboBox. I write the following sample based on
Macro Zhou's for your information.

[C# Code]

namespace WpfApplication4
{
public partial class Window1 : Window
{
public Window1()
{
InitializeCompo nent();
}
}

[ValueConversion (typeof(object) , typeof(String))]
public class MyToolTipConver ter : IValueConverter
{
public object Convert(object value, Type targetType, object
parameter, CultureInfo culture)
{
ComboBoxItem selectedItem = (ComboBoxItem)v alue;
//Return the tooltip of the current selected item;
return selectedItem.To olTip;
}

public object ConvertBack(obj ect value, Type targetType, object
parameter, CultureInfo culture)
{
return value;
}
}
}
[XAML code]

<Window x:Class="WpfApp lication4.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
xmlns:local="cl r-namespace:WpfAp plication4"
Title="Window1" Height="300" Width="300">

<Window.Resourc es>
<local:MyToolTi pConverter x:Key="myToolti pConverter"/>
</Window.Resource s>

<DockPanel>

<ComboBox x:Name="combo" SelectedIndex=" 0" DockPanel.Dock= "Top"
Height="23" Width="251">
<ComboBoxItem ToolTip="FirstI tem">one</ComboBoxItem>
<ComboBoxItem ToolTip="Second Item">two</ComboBoxItem>
<ComboBoxItem ToolTip="ThirdI tem">three</ComboBoxItem>
<ComboBox.ToolT ip>
<ToolTip DataContext="{B inding Path=PlacementT arget,
RelativeSource= {RelativeSource Self}}">
<TextBlock Text="{Binding Path=SelectedIt em,
Converter={Stat icResource myTooltipConver ter}}" Foreground="Gre en"/>
</ToolTip>
</ComboBox.ToolTi p>
</ComboBox>
</DockPanel>

</Window>
If any part of the sample code is unclear, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 6 '08 #3
Hi Wts,

You can use a converter in the template as well. For example:

[XAML code]

<Window x:Class="WpfApp lication4.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
xmlns:local="cl r-namespace:WpfAp plication4"
Title="Window1" Height="300" Width="300">

<Window.Resourc es>
<local:MyToolTi pConverter x:Key="myToolti pConverter"/>

<Style TargetType="Com boBox">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type ComboBox}">
<Border BorderBrush="Re d" BorderThickness ="3">
<Grid>
<ToggleButton Name="ToggleBut ton" />
<ContentPresent er Content="{Templ ateBinding
SelectionBoxIte m}">
<ContentPresent er.ToolTip>
<TextBlock Margin="0,0,100 ,50"
x:Name="textBlo ck"
Text="{Template Binding
SelectedItem, Converter={Stat icResource myTooltipConver ter}}"/>
</ContentPresente r.ToolTip>
</ContentPresente r>
</Grid>
</Border>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>

</Window.Resource s>

<DockPanel>

<ComboBox x:Name="combo2" SelectedIndex=" 0" DockPanel.Dock= "Top"
Height="23" Width="251">
<ComboBoxItem ToolTip="FirstI tem">one</ComboBoxItem>
<ComboBoxItem ToolTip="Second Item">two</ComboBoxItem>
<ComboBoxItem ToolTip="ThirdI tem">three</ComboBoxItem>
</ComboBox>

</DockPanel>

</Window>

=============== =============== =====

[C# code]

namespace WpfApplication4
{
public partial class Window1 : Window
{
public Window1()
{
InitializeCompo nent();
}
}

[ValueConversion (typeof(object) , typeof(String))]
public class MyToolTipConver ter : IValueConverter
{
public object Convert(object value, Type targetType, object
parameter, CultureInfo culture)
{
ComboBoxItem selectedItem = (ComboBoxItem)v alue;
return selectedItem.To olTip;
}

public object ConvertBack(obj ect value, Type targetType, object
parameter, CultureInfo culture)
{
return value;
}
}
}

Should you have any question, please don't hesitate to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7484
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the project, the combox box initially displays an empty selection. When I click on the drop down arrow I see the "Make a Selection" followed by the other choices. How can I move everything up so that the "Make a Selection" is the default value in...
1
6380
by: Rachel Suddeth | last post by:
When I put a ComboBox on a form, I can enter strings through the designer to fill Items collections. I have put a ComboBox in a UserControl, and exposed the the Items collections with the same type... public class ControlWithComboBox : MyControls.BaseControl, IDataEntryControl { ... protected System.Windows.Forms.ComboBox comboBox; ... public ComboBox.ObjectCollection Items
11
18355
by: Timo Kunze | last post by:
Hi! If you move the mouse over an item that's part of a treeview and wider than the treeview, a tooltip showing the full item text will be displayed. I try to do this for ListBoxes and ComboBoxes. For ListBoxes I got it working, but not for the ListBox part of ComboBoxes. Do you know any sample code? Thanks in advance! Timo
5
25834
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create some comboBox-es to show some data on them manually entered in the code without connecting to the database yet. It should be simple but somehow I can't make it work. First, I drag a comboBox from the ToolBox to the form. Then,
6
7805
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows the item count correctly
7
1902
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure why, but the items are not visible in the listbox or combobox until one of the items has been chosen. This of course is not good, since someone can not see the items they need to choose from. Any help would be appreciated.
0
1401
by: andreas.baus | last post by:
Hi. Does anyone have an idea if it's possible to display a tooltip on individual items in a combobox (in dropped-down state). That means, what I want to do is the following: when the user is about to select an item in the combobox (i.e., he has clicked on it to show the dropdown list) I want to display extended information (like a description) of whatever item in the list he is hovering his mouse cursor over *before* he makes any actual...
9
2427
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in another form. Problem is if I wake a tooltip when the window is floated, and then try the same thing when it is reparented, the app crashes with " Cannot access a disposed object.Object name: 'Form'. Presumably, this is a result of the tooltips...
5
6786
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to create a customized ComboBox where the methods ComboBox.Items.Add and ComboBox.Items.Insert will behave thusly: -- If the item is not present, add it. -- If the item is present, set the selected index to the item (without adding a duplicate). I know the basics of inheriting from user controls, so if this was merely overriding a method of ComboBox I could do it. But how does one go about overriding a method of the Items...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.