locked
Binding setter property in metro apps

    Question

  • Hi All,

    I have a requirement like binding the foreground color of a textblock in standardstyles.xaml file(Common file).

    i.e..

     <Style x:Key="TextButtonStyle" TargetType="Button">
            <Setter Property="MinWidth" Value="0"/>
            <Setter Property="MinHeight" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                            <TextBlock
                                x:Name="Text"
                                Text="{TemplateBinding Content}"                            
                                Margin="3,-7,3,10"
                                TextWrapping="NoWrap"
                                Style="{StaticResource SubheaderTextStyle}"/>
                            <Rectangle
                                x:Name="FocusVisualWhite"
                                IsHitTestVisible="False"
                                Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
                                StrokeEndLineCap="Square"
                                StrokeDashArray="1,1"
                                Opacity="0"
                                StrokeDashOffset="1.5"/>
    ......
                           </Style>

    the highlighted textblock color should be changed based on binding like

    foreground={Binding somecolor} ...
           

    I have checked the sample http://tonychampion.net/blog/index.php/2011/12/6th-day-of-silverlight-binding-in-style-setters/ in Silverlight. Even there also the style is defined within the page. But I need in resourcedictionary file.

    Any help would be appreciated.

    Thanks in advance.


    Nazia

    Wednesday, July 04, 2012 1:26 PM

All replies

  • Don't quite understand your question. If you simple want to bind the foreground color to somecolor, you can define a brush resource and binding the Foreground to it, like:

    TextBlockText="{TemplateBindingContent}" Foreground="{BindingSource={StaticResourceBrush1}}"

    Thursday, July 05, 2012 10:18 PM