Click here to Skip to main content
15,889,867 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Hmm ...MVVM ... Is this Bad? I can't decide Pin
Jammer22-Apr-11 10:38
Jammer22-Apr-11 10:38 
GeneralRe: Hmm ...MVVM ... Is this Bad? I can't decide Pin
Jammer25-Apr-11 22:38
Jammer25-Apr-11 22:38 
AnswerRe: Hmm ...MVVM ... Is this Bad? I can't decide [modified] Pin
BubingaMan28-Apr-11 1:59
BubingaMan28-Apr-11 1:59 
QuestionHow to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Rocky2320-Apr-11 2:24
Rocky2320-Apr-11 2:24 
AnswerRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Tarun.K.S20-Apr-11 3:05
Tarun.K.S20-Apr-11 3:05 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls [modified] Pin
Rocky2320-Apr-11 3:28
Rocky2320-Apr-11 3:28 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Tarun.K.S20-Apr-11 3:59
Tarun.K.S20-Apr-11 3:59 
AnswerRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Ian Shlasko20-Apr-11 3:57
Ian Shlasko20-Apr-11 3:57 
As Tarun tried to explain, this is really the wrong way to tackle this problem. You're trying to write a WPF application like a WinForms one, and that defeats the purpose entirely.

The key to WPF is Data Binding... The entire interface revolves around it, and if you switch your mind to the right track, it'll make your life much easier. All of that "glue" to connect controls, keep things synchronized, turn things on and off... All of that can be pretty much automatic.

First of all, you should try to AVOID giving names to your controls. If you have to refer to a control from the code-behind, you're either doing something really weird/original, or you're just doing it wrong.

1) Create a data model class... Just a simple class that contains a few properties to store the state of your GUI. In your situation, I think you'll need properties for:
a) A list representing the Directives. I'd type this as an ObservableCollection<Directive> to make sure updates are processed correctly.
b) A Directive representing the selected item ("SelectedDirective" maybe).

2) Set the DataContext of the window (Or anything that contains all of the related controls) to this model class, so the bindings will reference it

3) Bind the controls:
a) The ItemsSource of the listbox should bind to your list property
b) The SelectedItem of the listbox should bind to your SelectedDirective property, with Mode=TwoWay
c) The textboxes (txtDirectiveName, txtDirectiveDescription - Though you should un-name them after you do this) should bind to "SelectedDirective.DirectiveName" and "SelectedDirective.DirectiveDescription"
d) The delete button's "IsEnabled" property should bind to SelectedItem. For this, you need a converter that will take an object and return true if it's non-null.
e) The delete button's event handler can be as simple as Directives.Remove(SelectedDirective).

See how this works? The code-behind never refers directly to GUI controls, except to set the DataContext. The GUI does its own thing, and just reads and writes data to/from the underlying model.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)

GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Tarun.K.S20-Apr-11 4:09
Tarun.K.S20-Apr-11 4:09 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Ian Shlasko20-Apr-11 4:12
Ian Shlasko20-Apr-11 4:12 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Kunal Chowdhury «IN»20-Apr-11 22:44
professionalKunal Chowdhury «IN»20-Apr-11 22:44 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Rocky2327-Apr-11 19:49
Rocky2327-Apr-11 19:49 
GeneralRe: How to read the data from listbox Itemsource datatemplate and display it in UI controls Pin
Ian Shlasko28-Apr-11 1:41
Ian Shlasko28-Apr-11 1:41 
QuestionPulling controls from resources Pin
Jean-Louis Leroy19-Apr-11 2:51
Jean-Louis Leroy19-Apr-11 2:51 
AnswerRe: Pulling controls from resources Pin
Ian Shlasko19-Apr-11 5:56
Ian Shlasko19-Apr-11 5:56 
GeneralRe: Pulling controls from resources Pin
Jean-Louis Leroy19-Apr-11 23:00
Jean-Louis Leroy19-Apr-11 23:00 
GeneralRe: Pulling controls from resources Pin
Ian Shlasko20-Apr-11 2:40
Ian Shlasko20-Apr-11 2:40 
GeneralRe: Pulling controls from resources Pin
Jean-Louis Leroy20-Apr-11 3:00
Jean-Louis Leroy20-Apr-11 3:00 
QuestionHow To Create This Menu In WPF Pin
Kevin Marois18-Apr-11 10:49
professionalKevin Marois18-Apr-11 10:49 
AnswerRe: How To Create This Menu In WPF Pin
Pete O'Hanlon18-Apr-11 11:20
mvePete O'Hanlon18-Apr-11 11:20 
GeneralRe: How To Create This Menu In WPF Pin
Kevin Marois18-Apr-11 11:26
professionalKevin Marois18-Apr-11 11:26 
GeneralRe: How To Create This Menu In WPF Pin
Pete O'Hanlon18-Apr-11 11:31
mvePete O'Hanlon18-Apr-11 11:31 
GeneralRe: How To Create This Menu In WPF Pin
Kevin Marois19-Apr-11 5:22
professionalKevin Marois19-Apr-11 5:22 
GeneralRe: How To Create This Menu In WPF Pin
Pete O'Hanlon19-Apr-11 6:37
mvePete O'Hanlon19-Apr-11 6:37 
QuestionAnybody got TaskbarItemProgressState.Indeterminate to work? Pin
SledgeHammer0118-Apr-11 6:55
SledgeHammer0118-Apr-11 6:55 

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.