views:

1271

answers:

1

Is it possible to bind an additional resource string to another attribute within a control. I already have one attribute bound to a resource but also need another. I can't see a way of doing it as I would need an extra DataContext but oviously can only have one.

The additional attribute I need to bind to is Content within the hyperlink control.

The xaml file is as follows:-

<UserControl x:Class="SilverlightApplication1.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mystuff="clr-namespace:my.assembly.name;assembly=my.assembly.name"
    Width="100" Height="100">

    <UserControl.Resources>
        <mystuff:TxtResConv x:Key="TxtResConv" />
        <mystuff:TxtResPar x:Key="LabelTitle" ResourceUri="LabelTitle" DefaultValue="default label title" />
        <mystuff:TxtResPar x:Key="LinkURL" ResourceUri="LinkURL"  DefaultValue="default label title" />
    </UserControl.Resources>

   <Grid x:Name="LayoutRoot" Background="White">
            <HyperlinkButton DataContext="{StaticResource LinkURL}" x:Name="HyperLink1" Content="NEED TO ADD RESOURCE STRING LABELTITLE HERE !!" NavigateUri="{Binding Mode=OneWay,Converter={StaticResource TxtResConv}}"></HyperlinkButton>             
   </Grid>
</UserControl>

Thanks in advance.

+1  A: 

You use the Binding syntax to bind to the Content property in the same way you bind to the NavigateUri property. If it comes from a different source than LinkUri then you specify that in the binding syntax Source property:

Content="{Binding Source={StaticResource LabelTitle}, Converter={StaticResource TxtResConv}}"
Michael S. Scherotter
Thanks very much for this answer.
cyberbobcat