This is a migrated thread and some comments may be shown as answers.

Format bound value in xaml with formatString from resx-file

3 Answers 364 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 18 May 2011, 10:20 AM
Hi,

I have a RadMenuItem. Its header is bound to a  property of the DataContext. In addition I need the Header-Text to be formatted in the XAML with a String given in a resource file.

I tried the following which does NOT work:
<telerikNav:RadMenuItem StaysOpenOnClick="False">
     <telerikNav:RadMenuItem.Header>
            <TextBlock Text="{Binding name, StringFormat={Binding TXT001, Source={StaticResource ImpRes}}}">"></TextBlock>
     </telerikNav:RadMenuItem.Header>
</telerikNav:RadMenuItem>

In the forum I found someone doing this using the following code:
<MenuItem.Header>
    <TextBlock Text="{Binding Path=Name,
                 StringFormat={Resx
                 resxName=PSSPECApplication.Controls.ProjectControlResources,Key=load_ContextMenu_Save_Header},
                  Mode=OneWay}" />
</MenuItem.Header>

With this code I have the problem, that I don't know where Resx resxName, ... come from.

Could please someone provide me with a working example.

Thanks,
Stefan

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 19 May 2011, 08:16 AM
Hello Stefan,

You cannot bind to DataContext and set Source or RelativeSource at the same time.
One possible workaround is to use Converter property of Binding object and set some special converter that will get the Name property and then format it according to the Resource file.

Let us know if you need more information.

Greetings,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andreas
Top achievements
Rank 1
answered on 19 May 2011, 09:06 AM
Hello Hristo,

I already use a converter and this works fine. I was just wondering if there is a solution to this problem without having to create an additional converter class.

Thanks for your help,
Stefan
0
Accepted
Hristo
Telerik team
answered on 20 May 2011, 01:46 PM
Hello Stefan,

I don't think converter can be avoided here.
I think in Silverlight 5 this can be done with MarkupExtensions.

Kind regards,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Andreas
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or