In my resource file I have
LOCKER NO. {0} IS OPEN
I need to bind the resource file to a text box and want to dynamically set value in palce holder with foreground as red.
below shows my 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 to show a value inside {0} as red?
From code behind we can do
Title.Text = string.Format(Properties.Resources.LockerNumberIsOpen, (this.DataContext as OpenParcelViewModel).PrefixWithNumber);
var tr = this.Find((this.DataContext as 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 to do it in the XAML