Click here to Skip to main content
14,978,778 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: UI not updating Pin
Gerry Schmitz29-Mar-21 11:24
mveGerry Schmitz29-Mar-21 11:24 
GeneralRe: UI not updating Pin
#realJSOP29-Mar-21 12:07
mva#realJSOP29-Mar-21 12:07 
GeneralRe: UI not updating Pin
Gerry Schmitz29-Mar-21 12:19
mveGerry Schmitz29-Mar-21 12:19 
GeneralRe: UI not updating Pin
#realJSOP29-Mar-21 23:33
mva#realJSOP29-Mar-21 23:33 
GeneralRe: UI not updating Pin
Richard Deeming29-Mar-21 21:36
mveRichard Deeming29-Mar-21 21:36 
GeneralRe: UI not updating Pin
#realJSOP29-Mar-21 23:42
mva#realJSOP29-Mar-21 23:42 
GeneralRe: UI not updating Pin
Richard Deeming30-Mar-21 0:05
mveRichard Deeming30-Mar-21 0:05 
GeneralRe: UI not updating Pin
#realJSOP30-Mar-21 5:12
mva#realJSOP30-Mar-21 5:12 
So I did this (I'm gonna start using the actual object names because I'm too lazy to "obfuscate" them, and it makes it more consistent).

Notifiable is a class that implements INotifyPropertyChanged. I decided to inherit from this class because it already has the event mechanism built in (no point in reinventing the wheel).

public class Tfs : Notifiable
{
    public string CurrentAction{ get; set; }
    public string CurrentFile  { get; set; }
    public int    FileCount    { get; set; }

    // Keeps the event overhead to a dull roar - no need to post propertychanged events 
    // three times when once will do the job
    private int statusChanged;
    public  int  StatusChanged { get { return this.statusChanged; } set { this.statusChanged = value; this.NotifyPropertyChanged(); } }

    public void GetItemSet(int changeset, ref List<string> folders, ref List<FileBytes> files)
    {
        // gets the itemset from TFS and populates the folders and files collection
        // not included in the name of brevity
    }

    public void GetSpecificVersion(int changeset)
    {
        List<string> folders = new List<string>();
        List<FileBytes> files = new List<FileBytes>();

        this.CurrentAction = string.Concat("Retrieve item set - ");
        this.FileCount     = 0;
        this.CurrentFile   = this.AppFolder;
        this.StatusChanged = 1;

        this.GetItemSet(changeSet, ref folders, ref files);

		// create the folders we're going to need
        this.CurrentAction = "Create folder - ";
        foreach (string path in folders)
        {
            this.CurrentFile   = path;
            this.StatusChanged = 1;
            // we don't count files here, so don't update filecount
            this.CreateFolder(path);
        }

        this.CurrentAction = "Copy file - ";
        foreach (FileBytes file in files)
        {
            this.FileCount  += 1;
            this.CurrentFile = file.FilePath;
            this.StatusChanged = 1;

            // code to write the file to the disk (not included in the name of brevity)
        }
    }
}


My form code-behind looks like this (only relevant code included). WizardPageBase is derived from UserControl and implements INotifyPropertyChanged.
public class WizPgSelectVersion : WizardPageBase
{
    private string currentFile  ;
    private string currentAction;
    private int    fileCount    ;

    public string CurrentAction{get{return this.currentAction;} set{if(value!=this.currentAction){this.currentAction=value; this.NotifyPropertyChanged();}}}
    public string CurrentFile  {get{return this.currentFile  ;} set{if(value!=this.currentFile  ){this.currentFile  =value; this.NotifyPropertyChanged();}}}
    public int    FileCount    {get{return this.fileCount    ;} set{if(value!=this.fileCount    ){this.fileCount    =value; this.NotifyPropertyChanged();}}}
    public TFS    Tfs          { get; set; }

    protected override void OnVisibleChanged()
    {
        if (this.Visibility == Visibility.Visible)
        {
            this.Tfs = (this.Tfs == null) ? TFSSingleton.Instance.Tfs : this.Tfs;
            this.Tfs.PropertyChanged += this.Tfs_PropertyChanged;
        }
        else
        {
            if (this.Tfs != null)
            {
                this.Tfs.PropertyChanged -= this.Tfs_PropertyChanged;
            }
        }
    }

    // a variable just to see how many times the event handler was hit
    int eventCounter = ;

    private void Tfs_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        eventCounter++;
        this.CurrentAction = this.Tfs.CurrentAction;
        this.CurrentFile   = this.Tfs.CurrentFile;
        this.FileCount     = this.Tfs.FileCount;
    }

    private void BtnGetFilesFromTfs_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            // we pull files for all of the selected top-level applications
            foreach(VMSelectedApp app in appList)
            {
                // do some stuff - prepare the tfs object by setting paths and project names

                this.Tfs.GetSpecificVersion2(app.ChangeSet);

                // Do some stuff that parses the solution file for the app and retrieves 
                // dependency projects (which also calls Tfs.GetSpecificVersion2
            }
        }
        catch (Exception ex)
        {
        }        
    }
}


And finally, the bound controls in the xaml (they're in a stackpanel, but that seemed irrelevant to me). I omitted colors and margin info.
<TextBlock x:Name="textblockCurrentAction" Text="{Binding Path=CurrentAction}" />
<TextBlock x:Name="textblockCurrentFile" Text="{Binding Path=CurrentFile}" />
<TextBlock x:Name="textblockFileCount" Text="{Binding Path=FileCount}" />


When I run the code:
0) There are no binding exceptions shown in the output window.
1) The Tfs PropertyChanged event handler is in fact detecting the property changed event from the Tfs object.
2) The UI is not updating.
3) At the end of the process, the eventCounter value is 3666, which is the expected number of times it should be called.

I don't think I forgot anything, but let me know if something doesn't look right.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

GeneralRe: UI not updating Pin
#realJSOP30-Mar-21 12:14
mva#realJSOP30-Mar-21 12:14 
GeneralRe: UI not updating Pin
#realJSOP30-Mar-21 14:26
mva#realJSOP30-Mar-21 14:26 
QuestionImpossible? Get instance of MainWindow from extern WPF-application Pin
Mc_Topaz22-Mar-21 14:05
MemberMc_Topaz22-Mar-21 14:05 
AnswerRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Richard Deeming22-Mar-21 22:40
mveRichard Deeming22-Mar-21 22:40 
GeneralRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Mc_Topaz23-Mar-21 4:02
MemberMc_Topaz23-Mar-21 4:02 
AnswerRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Gerry Schmitz23-Mar-21 7:27
mveGerry Schmitz23-Mar-21 7:27 
GeneralRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Mc_Topaz23-Mar-21 12:22
MemberMc_Topaz23-Mar-21 12:22 
GeneralRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Richard Deeming23-Mar-21 23:14
mveRichard Deeming23-Mar-21 23:14 
GeneralRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Gerry Schmitz24-Mar-21 5:40
mveGerry Schmitz24-Mar-21 5:40 
GeneralRe: Impossible? Get instance of MainWindow from extern WPF-application Pin
Mc_Topaz25-Mar-21 0:02
MemberMc_Topaz25-Mar-21 0:02 
QuestionWPF DataGrid Custom Group Header Pin
Kevin Marois22-Mar-21 8:47
professionalKevin Marois22-Mar-21 8:47 
AnswerRe: WPF DataGrid Custom Group Header Pin
Richard Deeming22-Mar-21 22:35
mveRichard Deeming22-Mar-21 22:35 
QuestionDynamic WPF DataGrid Pin
Kevin Marois19-Mar-21 10:41
professionalKevin Marois19-Mar-21 10:41 
AnswerRe: Dynamic WPF DataGrid Pin
Richard Deeming21-Mar-21 22:50
mveRichard Deeming21-Mar-21 22:50 
GeneralRe: Dynamic WPF DataGrid Pin
Kevin Marois22-Mar-21 7:07
professionalKevin Marois22-Mar-21 7:07 
GeneralRe: Dynamic WPF DataGrid Pin
Kevin Marois23-Mar-21 9:58
professionalKevin Marois23-Mar-21 9:58 
GeneralRe: Dynamic WPF DataGrid Pin
Richard Deeming23-Mar-21 23:13
mveRichard Deeming23-Mar-21 23:13 

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.