The Contains() method is looking for you to pass in the actual TabItem you are looking for, so it won't help you. But this will work: var matchingItem = tab_main.Items.Cast() . Where(item => item.Name == accountNumber) .FirstOrDefault(); if(matchingItem!
=null) tab_main. SelectedItem = matchingItem; else.
The Contains() method is looking for you to pass in the actual TabItem you are looking for, so it won't help you. But this will work: var matchingItem = tab_main.Items.Cast() . Where(item => item.Name == accountNumber) .FirstOrDefault(); if(matchingItem!
=null) tab_main. SelectedItem = matchingItem; else ...
Ray, I took the liberty of editing in a call to Cast. TabControl. Items is IEnumerable but not IEnumerable so it doesn't directly support the LINQ Where operator directly.
– itowlson Feb 17 '10 at 0:47 Thank you. ---- – Ray Burns Feb 17 '10 at 0:52 Thanks for the replies! Before the edit it didn't work and I ended up coming up with another similar solution.
Certainly got me thinking in the right direction! I found a very similar solution but also had one follow up question that I will post as another answer if anyone has the time to help! – Terminal Frost Feb 17 '10 at 1:18.
Thanks for the replies! Before the edit it didn't work and I ended up coming up with another similar solution. Certainly got me thinking in the right direction!
I'm still not quite used to LINQ and lambda expressions. In case anyone else is looking for solutions this also worked for me: var matchingItem = from TabItem t in tab_main. Items where t.Name == searchHash select t; if (matchingItem.Count()!
= 0) tab_main. SelectedItem = matchingItem. ElementAt(0); else ... One final question if anyone is reading this... is there a more elegant way to select the element from matchingItem by referencing the name property versus assuming the correct element is at position 0?
There is not necessarily a "correct element" - more than one element can have the same Name property. If the names are registered using INameScope. RegisterName, then INameScope.
FindName will find it. However this is not a good design for several reasons which I will not enumerate here. With WPF you should be using MVVM design, not old WinForms-style design.
Look around StackOverflow and elsewhere to learn about MVVM. – Ray Burns Feb 17 '10 at 1:35 FYI: in general Stack Overflow encourages users to ask "follow up" questions as new questions rather than extending their existing questions. See the FAQ and discussions in meta.stackoverflow.Com for more information.
– Ray Burns Feb 17 '10 at 2:12 Cool thanks for the correction and pointing me to MVVM design. – Terminal Frost Feb 17 '10 at 2:46.
I am programmatically adding TabItems to my main TabControl, one for each account that the user chooses to open. Before creating and adding a new TabItem I would like to check if the user already has the account open in another tab. I do not want to end up with two identical tabs open.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.