在 silverlight 中,存在一个已知的文本框插入符错误,此处讨论:http://forums。 silverlight.net/p/165276/423268.aspx
作为解决方法,使用附加行为允许显式指定 TextBox 插入符号的颜色。
因此,我的 TextBox 样式有以下设置器:
<Style x:Key="NameEditStyle" TargetType="TextBox">
<Setter Property="Utilities:FixCaretBrushBehavior.CaretBrush" Value="White" />
我的应用程序在 Windows Phone 上运行,其中 TextBox 可以有白色和黑色背景。我需要有条件地修改插入符号是否显示为白色到黑色。 (这相当于设置属性的Value
)。
如何从代码中有条件地更改样式设置器中的此特定属性?
我尝试为属性提供 x:Name 并尝试在代码隐藏中引用它,但该属性始终为 null
,因此我无法调整它的值。
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" />
My application is running on Windows Phone, where there can be both White and Black backgrounds for the TextBoxes. I need to conditionally modify whether the caret will appear White to Black. (which is equivalent to setting a Value
of the property).
How can I conditionally change this particular property in a style setter from 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.
发布评论
评论(1)
WPF/SL/WP7 无法在加载后更改样式,因为 Style.IsSealed 将为 true。
您可以做的是在旧样式的基础上创建新样式,并将 TextBoxes 样式更改为新样式:
或者,您也可以在运行时创建此新样式,如 文章。
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:
Alternatively you can also create this new style during runtime as described here in the article.