Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

mui:LinkGroup & mui:Link DisplayName as DependencyProperty #3

Closed
picrap opened this issue Feb 25, 2015 · 6 comments
Closed

mui:LinkGroup & mui:Link DisplayName as DependencyProperty #3

picrap opened this issue Feb 25, 2015 · 6 comments

Comments

@picrap
Copy link

picrap commented Feb 25, 2015

Currently they are simple properties and can not be bound, making localization hard to achieve here.
Is it possible to turn them into DependencyProperty ?

@macgile
Copy link

macgile commented Feb 25, 2015

Hi picrap,

this can help
You can use WPFLocalizeExtension

consider this sample:

/*******************************/
In mainwindow.xaml
/**
*****************************/

<mui:Link DisplayName="customer"   Source="/Pages/Customer.xaml"  x:Name="CustomerLink" />

/*******************************/
In mainwindows.cs
/**
*****************************/
Loc.SetDisplayName(CustomerLink);

/*******************************/
In custom class Loc
/**
*****************************/
using WPFLocalizeExtension.Engine;
using WPFLocalizeExtension.Extensions;

private const string Prefix = "MyApp:Resource:";

     /// <summary>
    /// Localize LinkGroup DisplayName
    /// </summary>
    /// <param name="control"></param>
    public static void SetDisplayName(LinkGroup control)
    {
        SetDisplayName(control.DisplayName, control);
    }

    /// <summary>
    /// Localize Objct DisplayName
    /// </summary>
    /// <param name="key"></param>
    /// <param name="control"></param>
    public static void SetDisplayName(string key, object control)
    {
        var locTextExtension = new LocExtension(Prefix + key);

        // optional: set a forced culture -> the output stays the same
        // locTextExtension.ForceCulture = "en";
        // set the binding to the content property of the label
        locTextExtension.SetBinding(control, control.GetType().GetProperty("DisplayName"));
    }

@picrap
Copy link
Author

picrap commented Feb 26, 2015

I'll have a workaround solution soon, however I am still thinking that a DependencyProperty here may be a good thing. I'll see if I can submit you a pull request with proper change.

@picrap
Copy link
Author

picrap commented Feb 26, 2015

I have one question: why does the class NotifyPropertyChanged not inherit from DependencyObject? Basically, instead of using INotifyPropertyChanged, all properties could be implemented as dependency properties, which makes sense when in WPF controls.

@kozw
Copy link
Contributor

kozw commented Feb 26, 2015

It is certainly possible to change the Link properties to dependency properties, but I would advice against it, since the Link class is part of the Presentation layer in MVVM. Presentation classes are View agnostic, where a DependencyProperty implementation ties it to the View layer.

An interesting discussion about this at stack overflow: http://stackoverflow.com/questions/291518/inotifypropertychanged-vs-dependencyproperty-in-viewmodel

@picrap
Copy link
Author

picrap commented Feb 26, 2015

I agree with the discussion, which discusses of view-models. We tried a few years ago to use dependency properties in view-models, and it lead to a dead end: we had infinite loops with view, because of multithreading (as far as I remember).
However, the classes in Modern UI I'm talking about are related to the view, not the view-model. This is why I suggest here using dependency properties, exactly as all other controls do.
Anyway, you are the boss 😎

@picrap
Copy link
Author

picrap commented Mar 1, 2015

I submitted a pull request, so I close this issue.
(of course, up to you to accept or reject it)

@picrap picrap closed this as completed Mar 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants