xaml - Binding placeholder from resource file in WPF -
in resource file have
locker no. {0} open
i need bind resource file text box , want dynamically set value in palce holder foreground red.
below shows code
<textblock x:name="title" margin="0,70,0,0" horizontalalignment="center" verticalalignment="top" fontsize="42" fontweight="semibold" foreground="#888888" > <textblock.text> <multibinding stringformat="{x:static prop:resources.lockernumberisopen}"> <binding path="prefixwithnumber"/> </multibinding> </textblock.text> </textblock>
how show value inside {0} red?
from code behind can
title.text = string.format(properties.resources.lockernumberisopen, (this.datacontext openparcelviewmodel).prefixwithnumber); var tr = this.find((this.datacontext openparcelviewmodel).prefixwithnumber); tr.applypropertyvalue(textelement.foregroundproperty, "#9ebb2b"); private textrange find(string w) { var si = title.text.indexof(w); var sp = title.contentstart.getpositionatoffset(si + 1); var ep = title.contentstart.getpositionatoffset(si + w.length + 1); return new textrange(sp, ep); }
how in xaml
you need use richtextbox. allow set different colour text within block don't know how bind it. perhaps use method create object resource in format needed bind object.
in terms of setting seperate colours in richtextbox this question has in detail.