Click here to Skip to main content
15,898,035 members
Home / Discussions / WPF
   

WPF

 
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 
GeneralRe: WPF or WinForms? Pin
Gilliann13-Sep-09 5:12
Gilliann13-Sep-09 5:12 
AnswerRe: WPF or WinForms? Pin
jackson3529614-Sep-09 0:01
jackson3529614-Sep-09 0:01 
GeneralRe: WPF or WinForms? Pin
Pete O'Hanlon14-Sep-09 0:03
mvePete O'Hanlon14-Sep-09 0:03 
JokeRe: WPF or WinForms? Pin
Wes Aday15-Sep-09 9:03
professionalWes Aday15-Sep-09 9:03 
QuestionHow to select File Menu Items using Keyboard in WPF and C#? Pin
Krishna Aditya10-Sep-09 4:37
Krishna Aditya10-Sep-09 4:37 
AnswerRe: How to select File Menu Items using Keyboard in WPF and C#? Pin
Christian Graus10-Sep-09 12:31
protectorChristian Graus10-Sep-09 12:31 
AnswerRe: How to select File Menu Items using Keyboard in WPF and C#? Pin
ABitSmart10-Sep-09 15:18
ABitSmart10-Sep-09 15:18 
QuestionHow can I change the background color of the selected text in a textbox in xaml? Pin
Terkosh10-Sep-09 2:51
Terkosh10-Sep-09 2: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.