Click here to Skip to main content
13,864,512 members

Silverlight / WPF

 
AnswerRe: Looking for a windows phone 7.1 XNA programmer Pin
Richard MacCutchan26-Mar-13 1:09
protectorRichard MacCutchan26-Mar-13 1:09 
AnswerRe: Looking for a windows phone 7.1 XNA programmer Pin
Marco Bertschi26-Mar-13 2:15
protectorMarco Bertschi26-Mar-13 2:15 
QuestionCode-generated buttons in Stackpanel: how to handle events? Pin
Dirk.Bock22-Mar-13 13:24
memberDirk.Bock22-Mar-13 13:24 
AnswerRe: Code-generated buttons in Stackpanel: how to handle events? Pin
Mycroft Holmes22-Mar-13 15:14
memberMycroft Holmes22-Mar-13 15:14 
AnswerRe: Code-generated buttons in Stackpanel: how to handle events? Pin
Gerry Schmitz22-Mar-13 15:51
mveGerry Schmitz22-Mar-13 15:51 
QuestionMVVM Tasks and UI Updating Pin
cjb11022-Mar-13 2:44
membercjb11022-Mar-13 2:44 
AnswerRe: MVVM Tasks and UI Updating Pin
Matt T Heffron22-Mar-13 11:25
professionalMatt T Heffron22-Mar-13 11:25 
GeneralRe: MVVM Tasks and UI Updating Pin
cjb11024-Mar-13 23:37
membercjb11024-Mar-13 23:37 
Ok,

In my view XAML I think the only relevant bits are:
<UserControl.DataContext>
  <local:ViewModelLoadTest />
</UserControl.DataContext>

            <Button Height="32"

                    Width="128"

                    Margin="5"

                    Content="Run Test"

                    Command="{Binding RunTestCommand}"/>

<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible"

         FontFamily="Consolas"

         FontSize="12"

         ItemsSource="{Binding Path=Results}">
</ListBox>

I've tried some of the Binding options like Async.
There's nothing in the .xaml.cs file apart from the initialize call. Oh and its in a UserControl because my app has two modes so I'm using a tab control displaying two UserControls.

For my ViewModel, I've got an abstract base ViewModel then a design time and run time classes.
All the child classes do is set some properties, there's no other methods or additional properties.

In the base ViewModel class the collection is defined:
private ObservableCollection<string> _results = new ObservableCollection<string>();
public ObservableCollection<string> Results
{
    get { return _results; }
    set
    {
        _results = value;

        RaisePropertyChanged("Results");
    }
}

I've tried the creation of the collection in the constructor of the BaseViewModel and in the constructors of the child classes.

And in case its my Task stuff that's wrong:
private void DoRunTestCommand()
{
    _cancellationTokenSource = new CancellationTokenSource();

    Log(String.Format("Submitting {0} requests, every {1}ms, {2} at time."
        , Model.NumberOfRequests
        , Model.MSBetweenRequests
        , Model.NumberOfConcurrentRequests));

    CancellationToken cancellationToken = _cancellationTokenSource.Token;

    Task[] tasks = new Task[Model.NumberOfRequests];

    for (int i = 0; i < Model.NumberOfRequests; i++)
    {
        int idx = i;

        Task r = Task.Factory.StartNew((state) =>
            {
                SubmitRequest((int) state);

                cancellationToken.ThrowIfCancellationRequested();
            }
            , i
            , cancellationToken
            , TaskCreationOptions.LongRunning
            , TaskScheduler.FromCurrentSynchronizationContext());

        tasks[i] = r;

        Thread.Sleep(Model.MSBetweenRequests);
    }

    Log("Done");
}

private void SubmitRequest(int reqNum)
{

    Log(String.Format("{0} Started", reqNum));

    Thread.Sleep(1000);

    Log(String.Format("{0} Finished", reqNum));
}

private void Log(string text)
{
    Results.Add(String.Format("{0}: {1}", DateTime.Now, text));
}

Obviously SubmitRequest will do something else, I was just trying to get the UI working before I put the exact details in.
GeneralRe: MVVM Tasks and UI Updating Pin
cjb11025-Mar-13 2:56
membercjb11025-Mar-13 2:56 
GeneralRe: MVVM Tasks and UI Updating Pin
cjb11025-Mar-13 5:45
membercjb11025-Mar-13 5:45 
AnswerRe: MVVM Tasks and UI Updating Pin
Abhinav S25-Mar-13 8:26
memberAbhinav S25-Mar-13 8:26 
GeneralRe: MVVM Tasks and UI Updating Pin
cjb11025-Mar-13 8:36
membercjb11025-Mar-13 8:36 
QuestionProblems on ListView Control in WPF Pin
bikah chanda mohanta21-Mar-13 3:56
memberbikah chanda mohanta21-Mar-13 3:56 
AnswerRe: Problems on ListView Control in WPF Pin
Kenneth Haugland22-Mar-13 3:03
professionalKenneth Haugland22-Mar-13 3:03 
QuestionRoute Event for Button border Pin
Member 878633518-Mar-13 21:50
memberMember 878633518-Mar-13 21:50 
QuestionWPF treeview with circular reference not updating the childTreeviewItem Pin
geetha naidu17-Mar-13 1:39
membergeetha naidu17-Mar-13 1:39 
QuestionStack panel Pin
columbos1492715-Mar-13 10:35
membercolumbos1492715-Mar-13 10:35 
AnswerRe: Stack panel Pin
Gerry Schmitz15-Mar-13 12:01
mveGerry Schmitz15-Mar-13 12:01 
AnswerRe: Stack panel Pin
Mycroft Holmes15-Mar-13 14:30
memberMycroft Holmes15-Mar-13 14:30 
QuestionHow to add multiple button into same datacell in DataGrid column Pin
Jayantha Bandara15-Mar-13 1:45
memberJayantha Bandara15-Mar-13 1:45 
AnswerRe: How to add multiple button into same datacell in DataGrid column Pin
Pete O'Hanlon15-Mar-13 2:14
protectorPete O'Hanlon15-Mar-13 2:14 
AnswerRe: How to add multiple button into same datacell in DataGrid column Pin
Jayantha Bandara15-Mar-13 2:41
memberJayantha Bandara15-Mar-13 2:41 
GeneralRe: How to add multiple button into same datacell in DataGrid column Pin
Mycroft Holmes15-Mar-13 14:26
memberMycroft Holmes15-Mar-13 14:26 
QuestionLoading XAML at runtime Pin
Jayme6514-Mar-13 9:11
memberJayme6514-Mar-13 9:11 
AnswerRe: Loading XAML at runtime Pin
marimuthu2620-Mar-13 4:54
membermarimuthu2620-Mar-13 4:54 

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.


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190214.1 | Last Updated 14 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid