Click here to Skip to main content
15,909,051 members
Home / Discussions / WPF
   

WPF

 
Questionsilverlight Pin
Aryan198214-Sep-09 12:19
Aryan198214-Sep-09 12:19 
AnswerRe: silverlight Pin
Mark Salsbery15-Sep-09 5:08
Mark Salsbery15-Sep-09 5:08 
QuestionListBox displaying of items problem Pin
Zammy_bg14-Sep-09 4:00
Zammy_bg14-Sep-09 4:00 
AnswerRe: ListBox displaying of items problem Pin
Pete O'Hanlon14-Sep-09 4:42
mvePete O'Hanlon14-Sep-09 4:42 
GeneralRe: ListBox displaying of items problem Pin
Richard MacCutchan14-Sep-09 21:43
mveRichard MacCutchan14-Sep-09 21:43 
GeneralRe: ListBox displaying of items problem Pin
Pete O'Hanlon14-Sep-09 22:59
mvePete O'Hanlon14-Sep-09 22:59 
Questionidea/help in designing forum Pin
hrishiS14-Sep-09 1:14
hrishiS14-Sep-09 1:14 
AnswerRe: idea/help in designing forum Pin
Michael Sync14-Sep-09 1:54
Michael Sync14-Sep-09 1:54 
QuestionDynamically change the location of controls in silverlight Pin
Nekkantidivya13-Sep-09 20:36
Nekkantidivya13-Sep-09 20:36 
QuestionWPF animations hardware requirements Pin
koleraba13-Sep-09 11:12
koleraba13-Sep-09 11:12 
AnswerRe: WPF animations hardware requirements Pin
Christian Graus13-Sep-09 13:51
protectorChristian Graus13-Sep-09 13:51 
AnswerRe: WPF animations hardware requirements Pin
Mark Salsbery14-Sep-09 10:35
Mark Salsbery14-Sep-09 10:35 
QuestionCan I use excel spreadsheet as a datagrid In a WPF Client? Pin
bgundas12-Sep-09 12:08
bgundas12-Sep-09 12:08 
QuestionDyanmically assign source to a Medial element. Pin
Nekkantidivya12-Sep-09 2:01
Nekkantidivya12-Sep-09 2:01 
AnswerRe: Dyanmically assign source to a Medial element. Pin
Mark Salsbery12-Sep-09 7:14
Mark Salsbery12-Sep-09 7:14 
QuestionGetting ObservableCollection ThreadSafe Pin
ezazazel11-Sep-09 4:35
ezazazel11-Sep-09 4:35 
Hi guys!

Experiencing something weird recently.
Due to the fact, that my observable collection is the datacontext of my wpf app,
I need to make sure, that every Thread is able to add Elements.
Now the easy and working way is to add a
Dispatcher.Invoke(new Action(()=>{collection.Add(element}));
from every method being allowed to do so, which is kind of annoying.
So I thought it would be a good idea to add the functionality to the observable collection itself.
This is what I came up with:
class MElementsCollection :ObservableCollection<MElement>
    {
        #region Variables
        private Dispatcher mainDipatcher;

        public Dispatcher MainDipatcher
        {
            get {
                if (mainDipatcher == null)
                    mainDipatcher = App.MainDispatcher;
                return mainDipatcher; 
            }
        }
        #endregion

        public void AddThreadSafe(MElement mElement)
        {
            if (Thread.CurrentThread != MainDipatcher.Thread)
            {                
                    MainDipatcher.Invoke(new Action(() =>
                        {
                            this.Add(mElement);
                        }));
                
            }
            else
                this.Add(mElement);
        }
    }


Now what's actually happening is, that by adding many items short one after another, not every item is added to the collection but just for example every second one.

Can anyone please help me with this?

As always,
Thank you in advance
AnswerRe: Getting ObservableCollection ThreadSafe Pin
Pete O'Hanlon11-Sep-09 4:40
mvePete O'Hanlon11-Sep-09 4:40 
GeneralRe: Getting ObservableCollection ThreadSafe Pin
ezazazel11-Sep-09 5:08
ezazazel11-Sep-09 5:08 
QuestionSave the video from the Openfile dialog to a folder Pin
Nekkantidivya11-Sep-09 2:49
Nekkantidivya11-Sep-09 2:49 
QuestionUpload and display videos Pin
Nekkantidivya10-Sep-09 19:03
Nekkantidivya10-Sep-09 19:03 
AnswerRe: Upload and display videos Pin
Mark Salsbery11-Sep-09 6:31
Mark Salsbery11-Sep-09 6:31 
QuestionWPF or WinForms? Pin
Gilliann10-Sep-09 16:13
Gilliann10-Sep-09 16:13 
AnswerRe: WPF or WinForms? Pin
Christian Graus10-Sep-09 17:20
protectorChristian Graus10-Sep-09 17:20 
GeneralRe: WPF or WinForms? Pin
Ian Shlasko11-Sep-09 6:55
Ian Shlasko11-Sep-09 6:55 
AnswerRe: WPF or WinForms? Pin
BurNingFat12-Sep-09 21:41
BurNingFat12-Sep-09 21:41 

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.