在metro应用程序中绑定setter属性 [英] Binding setter property in metro apps

查看:101
本文介绍了在metro应用程序中绑定setter属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个要求就像在standardstyles.xaml文件(公共文件)中绑定文本块的前景色一样。



ie。

< Style x:Key =" TextButtonStyle"的TargetType = QUOT;按钮和QUOT;> 
< Setter Property =" MinWidth"值= QUOT; 0" />
< Setter Property =" MinHeight"值= QUOT; 0" />
< Setter Property =" Template">
< Setter.Value>
< ControlTemplate TargetType =" Button">
<网格背景="透明">
< TextBlock
x:Name =" Text"
Text =" {TemplateBinding Content}"
保证金=" 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>

突出显示的文本块颜色应根据

$ b等绑定进行更改$ b

前景= {绑定某种颜色} ... ...
       


我检查了样本 Silverlight中的
http://tonychampion.net/blog/index.php/2011/12/6th-day-of-silverlight-binding-in-style-setters/
。即使在页面中也定义了样式。但是我需要在resourcedictionary文件中。


任何帮助都将不胜感激。


提前致谢。


Nazia

解决方案

不太明白你的问题。如果您只想将前景颜色绑定到某些颜色,则可以定义画笔资源并将Foreground绑定到它,例如:


TextBlock 文字 =" { TemplateBinding 内容 }"   前景 =" { 绑定 来源 = { StaticResource Brush1 }}"



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

解决方案

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}}"


这篇关于在metro应用程序中绑定setter属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆