Format bound value in xaml with formatString from resx-file

4 posts, 1 answers
  1. Andreas
    Andreas avatar
    36 posts
    Member since:
    Sep 2008

    Posted 18 May 2011 Link to this post

    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
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 19 May 2011 Link to this post

    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
  3. Andreas
    Andreas avatar
    36 posts
    Member since:
    Sep 2008

    Posted 19 May 2011 Link to this post

    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
  4. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 20 May 2011 Link to this post

    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
Back to Top