Click here to Skip to main content
15,886,137 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: MVVM architecture Pin
Dean Oliver23-Jan-12 18:35
Dean Oliver23-Jan-12 18:35 
GeneralRe: MVVM architecture Pin
mi_n24-Jan-12 21:03
mi_n24-Jan-12 21:03 
AnswerRe: MVVM architecture Pin
Dean Oliver25-Jan-12 19:35
Dean Oliver25-Jan-12 19:35 
Questionconnectionstring Pin
arkiboys20-Jan-12 1:10
arkiboys20-Jan-12 1:10 
SuggestionRe: connectionstring Pin
Dean Oliver27-Jan-12 22:33
Dean Oliver27-Jan-12 22:33 
GeneralRe: connectionstring Pin
arkiboys28-Jan-12 20:19
arkiboys28-Jan-12 20:19 
QuestionWPF Listbox items Pin
programmervb.netc++19-Jan-12 7:22
programmervb.netc++19-Jan-12 7:22 
AnswerRe: WPF Listbox items Pin
Dean Oliver23-Jan-12 19:02
Dean Oliver23-Jan-12 19:02 
First of all out the box WPF wraps the listbox control in what is called a CollectionViewSource. This can provide you with information on the currently selectedItem as well as sorting and grouping items.
Get the CurrentItem and on your ObservableCollection of buttons just call IndexOf() and pass in the item. This should give you your index.

for exampe:
In your view xaml on the listbox set
IsSynchronizedWithCurrentItem="True"

then in your viewmodel (just bare inmind my collection is of themes)
C#
public MainViewModel()
      {
           _theme = new ObservableCollection<Themes>();

          _themesView = CollectionViewSource.GetDefaultView(_theme);
          _themesView.CurrentChanging += new CurrentChangingEventHandler(_themesView_CurrentChanging);
          _themesView.CurrentChanged += new EventHandler(_themesView_CurrentChanged);
      }


This allows you to than have access to the current item of the collection.
In the event below you can do whatever you want with the current object. eg; index of your button item that you have selected.
C#
void _themesView_CurrentChanged(object sender, EventArgs e)
      {
          ListCollectionView view = sender as ListCollectionView;
          int index = _theme.IndexOf(view.CurrentItem as Themes);
      }

Hope this helps to some extent.
QuestionHow to refer ViewModel from user-control code behind? Pin
sbkk16-Jan-12 11:54
sbkk16-Jan-12 11:54 
AnswerRe: How to refer ViewModel from user-control code behind? Pin
Mycroft Holmes16-Jan-12 13:07
professionalMycroft Holmes16-Jan-12 13:07 
AnswerRe: How to refer ViewModel from user-control code behind? Pin
Pete O'Hanlon16-Jan-12 22:29
mvePete O'Hanlon16-Jan-12 22:29 
GeneralRe: How to refer ViewModel from user-control code behind? Pin
sbkk17-Jan-12 4:59
sbkk17-Jan-12 4:59 
GeneralRe: How to refer ViewModel from user-control code behind? Pin
Pete O'Hanlon17-Jan-12 5:21
mvePete O'Hanlon17-Jan-12 5:21 
JokeRe: How to refer ViewModel from user-control code behind? Pin
Tom Delany24-Jan-12 11:25
Tom Delany24-Jan-12 11:25 
GeneralRe: How to refer ViewModel from user-control code behind? Pin
Pete O'Hanlon24-Jan-12 12:22
mvePete O'Hanlon24-Jan-12 12:22 
GeneralRe: How to refer ViewModel from user-control code behind? Pin
sbkk19-Jan-12 5:20
sbkk19-Jan-12 5:20 
GeneralRe: How to refer ViewModel from user-control code behind? Pin
sbkk25-Jan-12 3:44
sbkk25-Jan-12 3:44 
QuestionI wanna retrieve value from the hidden column in datagrid in silverlight 4 Pin
mdrizwan_115-Jan-12 18:35
mdrizwan_115-Jan-12 18:35 
AnswerRe: I wanna retrieve value from the hidden column in datagrid in silverlight 4 Pin
Mycroft Holmes15-Jan-12 20:59
professionalMycroft Holmes15-Jan-12 20:59 
GeneralRe: I wanna retrieve value from the hidden column in datagrid in silverlight 4 Pin
mdrizwan_115-Jan-12 22:03
mdrizwan_115-Jan-12 22:03 
GeneralRe: I wanna retrieve value from the hidden column in datagrid in silverlight 4 Pin
mdrizwan_116-Jan-12 23:28
mdrizwan_116-Jan-12 23:28 
QuestionAdding images to silverlight datagrid Pin
sudheesh kumar s14-Jan-12 0:51
sudheesh kumar s14-Jan-12 0:51 
AnswerRe: Adding images to silverlight datagrid Pin
AbhijeetB14-Jan-12 22:05
AbhijeetB14-Jan-12 22:05 
QuestionSlilverlight with WCF Pin
sudheesh kumar s14-Jan-12 0:36
sudheesh kumar s14-Jan-12 0:36 
AnswerRe: Slilverlight with WCF Pin
Pete O'Hanlon14-Jan-12 0:51
mvePete O'Hanlon14-Jan-12 0:51 

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.