Click here to Skip to main content
15,609,864 members
Home / Discussions / WPF


GeneralRe: WPF TextBox Handle Data Pasted In Pin
Kevin Marois15-Apr-21 5:49
professionalKevin Marois15-Apr-21 5:49 
QuestionFormat Percentage Pin
Kevin Marois13-Apr-21 9:16
professionalKevin Marois13-Apr-21 9:16 
AnswerRe: Format Percentage Pin
Richard Deeming13-Apr-21 22:36
mveRichard Deeming13-Apr-21 22:36 
GeneralRe: Format Percentage Pin
Kevin Marois14-Apr-21 7:42
professionalKevin Marois14-Apr-21 7:42 
QuestionAvalonEdit Sytax Highlighting for XAML files? Pin
#realJSOP5-Apr-21 8:57
mva#realJSOP5-Apr-21 8:57 
AnswerRe: AvalonEdit Sytax Highlighting for XAML files? Pin
Richard Deeming6-Apr-21 0:22
mveRichard Deeming6-Apr-21 0:22 
QuestionRevert Property Change Pin
Kevin Marois5-Apr-21 7:20
professionalKevin Marois5-Apr-21 7:20 
AnswerRe: Revert Property Change Pin
#realJSOP5-Apr-21 8:55
mva#realJSOP5-Apr-21 8:55 
QuestionUI not updating Pin
#realJSOP28-Mar-21 3:52
mva#realJSOP28-Mar-21 3:52 
AnswerRe: UI not updating Pin
Pete O'Hanlon28-Mar-21 6:10
subeditorPete O'Hanlon28-Mar-21 6:10 
GeneralRe: UI not updating Pin
#realJSOP28-Mar-21 6:40
mva#realJSOP28-Mar-21 6:40 
AnswerRe: UI not updating Pin
Richard Deeming28-Mar-21 22:20
mveRichard Deeming28-Mar-21 22:20 
GeneralRe: UI not updating Pin
#realJSOP29-Mar-21 2:59
mva#realJSOP29-Mar-21 2:59 
AnswerRe: UI not updating Pin
Gerry Schmitz29-Mar-21 9:15
mveGerry Schmitz29-Mar-21 9:15 
GeneralRe: UI not updating Pin
#realJSOP29-Mar-21 10:38
mva#realJSOP29-Mar-21 10:38 
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.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;
            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)
        this.CurrentAction = this.Tfs.CurrentAction;
        this.CurrentFile   = this.Tfs.CurrentFile;
        this.FileCount     = this.Tfs.FileCount;

    private void BtnGetFilesFromTfs_Click(object sender, RoutedEventArgs e)
            // 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


                // 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 

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.