0

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

Justin CI
  • 2,693
  • 1
  • 16
  • 34

1 Answers1

0

You need to use a richTextBox. that will allow you to set different colour for text within the block but I don't know how to bind it. Perhaps use a method to create an object with the resource in the format needed then bind it to that object.

In terms of setting seperate colours in a RichtextBox this question has it in detail.

Community
  • 1
  • 1
Sarfaraaz
  • 488
  • 6
  • 17
  • I used multibinding for place holder,but making foreground color red still an issue. Note:Edited the question – Justin CI Apr 23 '15 at 09:05