Click here to Skip to main content
15,891,976 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Problem Setting Focus Pin
Richard Deeming24-May-21 21:56
mveRichard Deeming24-May-21 21:56 
QuestionImpossible to override a value in an animation located in a style? Pin
Mc_Topaz20-May-21 6:51
Mc_Topaz20-May-21 6:51 
AnswerRe: Impossible to override a value in an animation located in a style? Pin
Gerry Schmitz20-May-21 8:08
mveGerry Schmitz20-May-21 8:08 
QuestionApp Security Behavior Pin
Kevin Marois20-May-21 6:09
professionalKevin Marois20-May-21 6:09 
QuestionOverride a value in base style's resource Pin
Mc_Topaz20-May-21 2:45
Mc_Topaz20-May-21 2:45 
AnswerRe: Override a value in base style's resource Pin
Richard Deeming20-May-21 4:33
mveRichard Deeming20-May-21 4:33 
GeneralRe: Override a value in base style's resource Pin
Mc_Topaz20-May-21 6:00
Mc_Topaz20-May-21 6:00 
QuestionApply TextBlock Captions at Runtime Pin
Kevin Marois14-May-21 9:34
professionalKevin Marois14-May-21 9:34 
AnswerRe: Apply TextBlock Captions at Runtime Pin
Peter_in_278014-May-21 13:36
professionalPeter_in_278014-May-21 13:36 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Kevin Marois14-May-21 13:42
professionalKevin Marois14-May-21 13:42 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Pete O'Hanlon14-May-21 23:51
mvePete O'Hanlon14-May-21 23:51 
AnswerRe: Apply TextBlock Captions at Runtime Pin
Mycroft Holmes15-May-21 12:25
professionalMycroft Holmes15-May-21 12:25 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Gerry Schmitz16-May-21 11:17
mveGerry Schmitz16-May-21 11:17 
QuestionWPF TextBox Handle Data Pasted In Pin
Kevin Marois14-Apr-21 8:29
professionalKevin Marois14-Apr-21 8:29 
AnswerRe: WPF TextBox Handle Data Pasted In Pin
Richard Deeming14-Apr-21 22:50
mveRichard Deeming14-Apr-21 22:50 
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
mve#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
mve#realJSOP5-Apr-21 8:55 
QuestionUI not updating Pin
#realJSOP28-Mar-21 3:52
mve#realJSOP28-Mar-21 3:52 
VS 2017
.Net 4.72
-------------------------------
I'm writing a WPF app that instantiates a class like this:
C#
public class MyClass : INotifyPropertyChanged
{
    private string currentFile;
    private int    fileCount  ;
    public string CurrentFile 
    { 
        get {return this.currentFile;} 
        set {if(value!=this.currentFile){this.currentFile=value;this.NtfyPropChange();}}
    }
    public int FileCount
    { 
        get {return this.fileCount;} 
        set {if (value != this.fileCount){this.fileCount=value;this.NtfyPropChange();}}
    }

    public MyClass()
    {
        this.CurrentFile = string.Empty;
        this.FileCount   = 0;
    }

    public void DoSomethingWithFiles()
    {
        string[] files = Directory,.GetFiles(@"c:\mypath", *.*);
        foreach(string file in files)
        {
            this.CurrentFile = file;
            this.FileCount += 1;
        }
    }
}


In the XAML, I'm binding like this:
<TextBlock Text="{Binding x:Name="textblockCurrentFile" Path=myObject.CurrentFile}"/>
<TextBlock Text="{Binding x:Name="textblockFileCount" Path=myObject.FileCount}"/>


In my INotifyPropertyChanged-derived form, I have set the DataContext, instantiated MyObject, and when I inspect everything under the debugger, the two MyObject properties in question are being updated as expected as the method loop proceeds. In fact, if I hook the MyObject.PropertyChanged event in the form code, it is indeed called for every property change event.

Problem:

The form controls that are bound to these properties don't update when the property values change.

The MyObject class is created on the UI thread, and the method is not, itself, being executed in a different thread.

What am I dong wrong (or not doing at all)?

I tried doing this in the PropertyChanged event handler in the form, but it didn't fix my problem:

C#
private void Tfs_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() => 
    {
        this.textblockCurrentFile.Text = this.myObject.CurrentFile;
        this.textblockFileCount.Text = this.myObject.FileCount.ToString();
    }));
}

".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

AnswerRe: UI not updating Pin
Pete O'Hanlon28-Mar-21 6:10
mvePete O'Hanlon28-Mar-21 6:10 

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.