Click here to Skip to main content
15,909,030 members
Home / Discussions / WPF
   

WPF

 
QuestionUpdate Instance Property From DP Pin
Kevin Marois29-Apr-14 6:29
professionalKevin Marois29-Apr-14 6:29 
I have a DP called FullName. When it changes, I need to parse it and add it to an instance property of type List<<string>> FileAsOptions.

So, when I have

"Joe Smith"

or

"Smith, Joe"

they both get added to the list property.

The FullName property is a DP, and the FileAsOptions is an instance property. It's not a DP because I don't want it to be bindable.

So the FullName DP's change callback calls a private method that parses the name and add it to the instance list

The problem is that the instance property needs to call RaisePropertyChanged, which only works on instance properties. So the property cannot be static.

Here's the code:

public partial class ContactCard : _UserControlBase
{
    public ContactCard()
    {
        InitializeComponent();
        LayoutRoot.DataContext = this;
    }

    private List<string> _FileAsOptions;
    public List<string> FileAsOptions
    {
        get { return _FileAsOptions; }
        set
        {
            if (_FileAsOptions != value)
            {
                _FileAsOptions = value;
                RaisePropertyChanged("FileAsOptions");
            }
        }
    }

    public string FullName
    {
        get { return (string)GetValue(FullNameProperty); }
        set { SetValue(FullNameProperty, value); }
    }

    public static readonly DependencyProperty FullNameProperty = DependencyProperty.Register(
        "FullName", typeof(string), typeof(ContactCard),
        new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnFullNamePropertyChanged)));

    private static void OnFullNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var card = sender as ContactCard;

        // ========== THIS DOESN'T COMPILE ==========
        //setFileAsOptions(card.FullName);
    }        
        
    private void setFileAsOptions(string fullName)
    {
        FileAsOptions = new List<string>();

        if (!string.IsNullOrEmpty(fullName))
        {
            string[] words = fullName.Split(' ');

            if (words.Length == 1)
            {
                FileAsOptions.Add(words[0]);
            }

            if (words.Length == 2)
            {
                FileAsOptions.Add(string.Format("{0} {1}", words[0], words[1]));
                FileAsOptions.Add(string.Format("{0}, {1}", words[1], words[0]));
            }

            // Other options here...
        }
    }
}


In summary, I need to be able to call the setFileAsOptions from the DP, which is static.

What's the right approach here?
If it's not broken, fix it until it is

AnswerRe: Update Instance Property From DP Pin
Richard Deeming29-Apr-14 6:34
mveRichard Deeming29-Apr-14 6:34 
GeneralRe: Update Instance Property From DP Pin
Kevin Marois29-Apr-14 6:37
professionalKevin Marois29-Apr-14 6:37 
QuestionWPF Style Question Pin
Kevin Marois28-Apr-14 7:18
professionalKevin Marois28-Apr-14 7:18 
AnswerRe: WPF Style Question Pin
Pete O'Hanlon28-Apr-14 7:24
mvePete O'Hanlon28-Apr-14 7:24 
GeneralRe: WPF Style Question Pin
Kevin Marois28-Apr-14 7:27
professionalKevin Marois28-Apr-14 7:27 
GeneralRe: WPF Style Question Pin
Pete O'Hanlon28-Apr-14 8:09
mvePete O'Hanlon28-Apr-14 8:09 
AnswerRe: WPF Style Question Pin
pradeep surya10-May-14 5:37
pradeep surya10-May-14 5:37 
QuestionPass Logging Method Pin
Kevin Marois24-Apr-14 12:01
professionalKevin Marois24-Apr-14 12:01 
AnswerRe: Pass Logging Method Pin
Matt T Heffron24-Apr-14 12:49
professionalMatt T Heffron24-Apr-14 12:49 
QuestionWPF TextBlock Trigger Question Pin
Kevin Marois24-Apr-14 7:45
professionalKevin Marois24-Apr-14 7:45 
AnswerRe: WPF TextBlock Trigger Question Pin
Richard Deeming24-Apr-14 8:24
mveRichard Deeming24-Apr-14 8:24 
GeneralRe: WPF TextBlock Trigger Question Pin
Kevin Marois24-Apr-14 8:53
professionalKevin Marois24-Apr-14 8:53 
GeneralRe: WPF TextBlock Trigger Question Pin
BubingaMan4-May-14 22:48
BubingaMan4-May-14 22:48 
QuestionI need develop Deepzoom fitBounds Method Pin
joajngwon23-Apr-14 19:58
joajngwon23-Apr-14 19:58 
QuestionWPF MVVM Set Focus Pin
Kevin Marois23-Apr-14 17:46
professionalKevin Marois23-Apr-14 17:46 
QuestionChange application language at Runtime Pin
sifi mohamed amine15-Apr-14 5:40
sifi mohamed amine15-Apr-14 5:40 
SuggestionRe: Change application language at Runtime Pin
Richard Deeming15-Apr-14 5:53
mveRichard Deeming15-Apr-14 5:53 
AnswerRe: Change application language at Runtime Pin
Andy41119-May-14 2:56
Andy41119-May-14 2:56 
QuestionLocalization in WPF MVVM Pin
sifi mohamed amine14-Apr-14 23:42
sifi mohamed amine14-Apr-14 23:42 
AnswerRe: Localization in WPF MVVM Pin
Vincent Beek16-Apr-14 6:57
Vincent Beek16-Apr-14 6:57 
QuestionUpdating Composition Tree from Visual Tree Pin
Ronald M. Martin14-Apr-14 12:18
Ronald M. Martin14-Apr-14 12:18 
QuestionHow to add all recommended icon sizes to WPF desktop application? Pin
Matt T Heffron14-Apr-14 11:49
professionalMatt T Heffron14-Apr-14 11:49 
AnswerRe: How to add all recommended icon sizes to WPF desktop application? Pin
Matt T Heffron14-Apr-14 13:44
professionalMatt T Heffron14-Apr-14 13:44 
QuestionHow to get TreeView SelectedItem/Value? Pin
BeeDev11-Apr-14 10:52
BeeDev11-Apr-14 10:52 

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.