c# - Binding for Localization -
i'm working on solution localization problem. isn't normal language localisation.
<label content="{binding mydictionary[a test], fallbackvalue=a test}"/>
in practice above code calls dictionary in view model, declared as
public dictionary<string, string> mydictionary
the problem have define string "a test" twice in label. once in index in binding, , again in fallbackvalue.
what end looks this...
<label content="{binding mydictionary[a test]}"/>
at moment happens when xaml designer in visual studio can't resolve mydictionary (as won't know datacontext can't hook viewmodel it's defined) means label display blank, won't make visual design harder.
i've looked calling static method mydictionary function properly, needs instantiated in view model.
is there way of having either index value "a test" show in designer without having use fallback value?
the goal able have content refreshed if value in mydictionary[a test]
updated (in reality mydictionary observable)
as won't know datacontext can't hook viewmodel it's defined
not so.... 1 can use design time context specifying in page's meta data atttributes such as:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d:datacontext="{d:designinstance {x:type viewmodels:mainvm}}"
by doing can setup design time dictionary use.
read here in msdn magazine:
mvvm - maximizing visual designer’s usage design-time data
note 1 can still use blend namespaces in non blend editors such visual studio. otherwise don't afraid use/learn blend needed.
if actual vm real data, in design mode ignore objects/actions may cause issues. here check determine if action in design mode, if not executes block, otherwise ignored because in design mode.
if (!designerproperties.getisindesignmode(this))
Comments
Post a Comment