从$ C $设置样式二传手值在运行C-背后 [英] Set Style Setter value from code-behind at runtime

查看:126
本文介绍了从$ C $设置样式二传手值在运行C-背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Silverlight中,还有一个就是这里讨论一个已知的文本框插入符号的错误: HTTP:/ /forums.silverlight.net/p/165276/423268.aspx

In silverlight, there is a known textbox caret bug that is discussed here: http://forums.silverlight.net/p/165276/423268.aspx

作为一种解决方法,一个附加行为被用来允许指定明确的文本框插入符号的颜色。

As a workaround, an attached behaviour is used that allows to specify the color for TextBox caret explicitly.

所以我在我的文本框的风格以下二传手:

Therefore I have the following setter in my TextBox style:

<Style x:Key="NameEditStyle" TargetType="TextBox">
            <Setter Property="Utilities:FixCaretBrushBehavior.CaretBrush" Value="White" />

我的应用程序在Windows Phone上,那里既可以是白色和黑色背景的文本框运行。我需要有条件地修改插入符是否会出现白到黑。 (相当于设置的属性)。

我如何有条件地从code的风格二传手改变这种特殊的属性?

How can I conditionally change this particular property in a style setter from code?

我试图给一个属性一个x:名称,并试图引用它在code-落后,但物业始终,这样我就可以'牛逼调整它的价值。

I have tried giving a property an x:Name and trying to reference it in code-behind, but the property is always null, so I can't adjust it's value.

推荐答案

还有就是加载之后就没有办法在WPF / SL / WP7改变风格,因为的 Style.IsSealed 将是真实的。 你可以做的是创造新的风格的基础上旧的,改变文本框的方式以适应新的风格:

There is no way in WPF/SL/WP7 to change a style after it is loaded because the Style.IsSealed will be true. What you can do is to create new style based on the old one and change the TextBoxes style to the new style:

<Style x:Key="NameEditStyle" TargetType="TextBox">
    <Setter Property="Utilities:FixCaretBrushBehavior.CaretBrush" Value="White" />
    ...
</Style>

<Style x:Key="BlackNameEditStyle" TargetType="TextBox" BasedOn="{StaticResource NameEditStyle}">
    <Setter Property="Utilities:FixCaretBrushBehavior.CaretBrush" Value="Black" />
</Style>

另外,您还可以在运行时作为的文章

这篇关于从$ C $设置样式二传手值在运行C-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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