Click here to Skip to main content
15,900,725 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Equivalent of treeView1.Nodes.Find in WPF TreeView ? Pin
Pete O'Hanlon13-Jan-10 8:46
mvePete O'Hanlon13-Jan-10 8:46 
GeneralRe: Equivalent of treeView1.Nodes.Find in WPF TreeView ? Pin
Mohammad Dayyan14-Jan-10 2:53
Mohammad Dayyan14-Jan-10 2:53 
GeneralRe: Equivalent of treeView1.Nodes.Find in WPF TreeView ? Pin
Pete O'Hanlon14-Jan-10 10:47
mvePete O'Hanlon14-Jan-10 10:47 
QuestionHow can I bind data from one combo box to another ? Pin
gil eichenbaum12-Jan-10 2:47
gil eichenbaum12-Jan-10 2:47 
AnswerRe: How can I bind data from one combo box to another ? Pin
Pete O'Hanlon12-Jan-10 3:42
mvePete O'Hanlon12-Jan-10 3:42 
GeneralRe: How can I bind data from one combo box to another ? Pin
gil eichenbaum12-Jan-10 5:34
gil eichenbaum12-Jan-10 5:34 
Questionbinding Path Fill to Hashtable item property Pin
DTh197810-Jan-10 11:21
DTh197810-Jan-10 11:21 
AnswerRe: binding Path Fill to Hashtable item property Pin
AspDotNetDev11-Jan-10 15:55
protectorAspDotNetDev11-Jan-10 15:55 
I think the problem is that when you attempt to bind to a hastable, WPF for some reason assumes that the value you pass in as the key is a string rather than an integer. One solution would be to have the keys in your hashtable be strings rather than numeric types (assuming you are currently using a numeric type). You could also convert your hashtable to a Dictionary, which is strongly typed and which WPF seems to have no problem binding to. However, it seems you were given the hashtable, so maybe you don't want to modify the collection. The alternative would be to implement IValueConverter and pass in the hash table as the value to convert and the key as the parameter. The converter would then get the value at that key. You will want to make sure the converter actually uses a key of the correct type. So, if the XAML passes in a string but the key is supposed to be an integer, you will want to use int.Parse to get the integer before using it on the dictionary. I will leave implementing the IValueConverter as an exercise for the reader (namely, you), but here is the alternative approach I talked about:
C#
// This is a property on the main window.
public System.Collections.Hashtable MyHashTable
{
	get
	{
		System.Collections.Hashtable table = new System.Collections.Hashtable();
		table["5"] = new SolidColorBrush(Colors.Red);
		return table;
	}
}

XML
<Window
    x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Name="MyWindow"
    Title="Window1">
    <Grid>
        <!-- When you run this, the path will be the color red. -->
        <Path
            Data="M 100,200 C 100,25 400,350 400,175 H 280"
            Fill="{Binding ElementName=MyWindow, Path=MyHashTable[5]}" />
    </Grid>
</Window>

As one final note, you could also create your own Dictionary type that just wraps a hastable. So, you pass the hashtable to the constructor of your HashWrapper (which acts like a strongly typed Dictionary) and when a key is passed to it, it just passes that key on to the wrapped hashtable and then casts the result into the correct type. The converter option is probably better than this one, but I thought I'd mention this one in case it matched up with your skills more appropriately.


GeneralRe: binding Path Fill to Hashtable item property Pin
DTh197811-Jan-10 19:27
DTh197811-Jan-10 19:27 
QuestionData Binding Pin
#realJSOP9-Jan-10 2:59
professional#realJSOP9-Jan-10 2:59 
AnswerRe: Data Binding Pin
Daniel Vaughan9-Jan-10 5:45
Daniel Vaughan9-Jan-10 5:45 
GeneralRe: Data Binding Pin
Lutosław12-Jan-10 4:05
Lutosław12-Jan-10 4:05 
GeneralRe: Data Binding Pin
Daniel Vaughan12-Jan-10 5:47
Daniel Vaughan12-Jan-10 5:47 
GeneralRe: Data Binding Pin
Abhinav S12-Jan-10 16:26
Abhinav S12-Jan-10 16:26 
GeneralRe: Data Binding Pin
Daniel Vaughan13-Jan-10 22:25
Daniel Vaughan13-Jan-10 22:25 
AnswerRe: Data Binding Pin
Kubajzz9-Jan-10 5:55
Kubajzz9-Jan-10 5:55 
QuestionThe name 'ImageListViewItem' does not exist in the current context ? Pin
Mohammad Dayyan8-Jan-10 17:56
Mohammad Dayyan8-Jan-10 17:56 
AnswerRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Abhinav S8-Jan-10 18:28
Abhinav S8-Jan-10 18:28 
GeneralRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Mohammad Dayyan8-Jan-10 22:46
Mohammad Dayyan8-Jan-10 22:46 
AnswerRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Abhinav S8-Jan-10 23:11
Abhinav S8-Jan-10 23:11 
GeneralRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Mohammad Dayyan8-Jan-10 23:13
Mohammad Dayyan8-Jan-10 23:13 
GeneralRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Mohammad Dayyan8-Jan-10 23:24
Mohammad Dayyan8-Jan-10 23:24 
AnswerRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
AspDotNetDev8-Jan-10 21:23
protectorAspDotNetDev8-Jan-10 21:23 
AnswerRe: The name 'ImageListViewItem' does not exist in the current context ? Pin
Pete O'Hanlon9-Jan-10 2:13
mvePete O'Hanlon9-Jan-10 2:13 
Questiongeneral help Pin
hotthoughtguy8-Jan-10 8:20
hotthoughtguy8-Jan-10 8:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.