gpt4 book ai didi

silverlight-4.0 - Silverlight 样式使插入符号消失?

转载 作者:行者123 更新时间:2023-12-04 16:12:46 27 4
gpt4 key购买 nike

我必须制作一个暗银光 UI。这很痛苦,所有控件都是黑色的,文本是白色的。我还想更改文本框中的插入符号颜色。由于我不想讨论的原因,我为 TextBoxes 创建了一个 Style(名为 BaseTextBoxStyle),并且我也为它们创建了一个隐式 Style,这是基于前面提到的 BaseTextBoxStyle。我使用 Blend 编辑了所有样式和模板,使用“编辑副本”命令,除了颜色和画笔之外,我没有更改模板中的任何内容。

现在我的文本框和我玩了一个有趣的游戏。他们使插入符号消失。我试图识别这些消失的模式,但我唯一确定的是,我单击的第一个 TextBox 显示插入符号正常。但是一些点击后插入符号从一些(或有时全部)TextBox 中消失。 (它不会切换回黑色,也不会出现在框中。)

如果我不理会 CaretBrush,就不会出现这个问题。但后来它是黑色的,所以我几乎看不到它。任何想法可能会导致这样的事情?

这是 XAML:

<Style x:Key="BaseTextBoxStyle" TargetType="TextBox">
<Setter Property="CaretBrush" Value="{StaticResource SolidHighBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background" Value="{StaticResource LinearMain}"/>
<Setter Property="BorderBrush" Value="{StaticResource LinearBase}"/>
<Setter Property="Foreground" Value="{StaticResource SolidStrongBrush}"/>
<Setter Property="SelectionBackground" Value="{StaticResource SolidHigh2Brush}"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid x:Name="RootElement">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0" To="#FF454545" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="MouseOverBorder"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
</Storyboard>
</VisualState>
<VisualState x:Name="ReadOnly">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ReadOnlyVisualElement"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused">
<Storyboard>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="Valid"/>
<VisualState x:Name="InvalidUnfocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ValidationErrorElement">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="InvalidFocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ValidationErrorElement">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" Storyboard.TargetName="validationTooltip">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>True</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="1" Opacity="1">
<Grid>
<Border x:Name="ReadOnlyVisualElement" Background="#5EC9C9C9" Opacity="0"/>
<Border x:Name="MouseOverBorder" BorderBrush="#00CC832B" BorderThickness="1">
<ScrollViewer x:Name="ContentElement" BorderThickness="0" IsTabStop="False" Padding="{TemplateBinding Padding}"/>
</Border>
</Grid>
</Border>
<Border x:Name="DisabledVisualElement" BorderBrush="#A5F7F7F7" BorderThickness="{TemplateBinding BorderThickness}" Background="#A5F7F7F7" IsHitTestVisible="False" Opacity="0"/>
<Border x:Name="FocusVisualElement" BorderBrush="{StaticResource SolidHigh2Brush}" BorderThickness="{TemplateBinding BorderThickness}" IsHitTestVisible="False" Margin="1" Opacity="0"/>
<Border x:Name="ValidationErrorElement" BorderBrush="#FFDB000C" BorderThickness="1" CornerRadius="1" Visibility="Collapsed">
<ToolTipService.ToolTip>
<ToolTip x:Name="validationTooltip" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" Placement="Top" PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Template="{StaticResource ValidationToolTipTemplate}">
<ToolTip.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="validationTooltip">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>true</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ToolTip.Triggers>
</ToolTip>
</ToolTipService.ToolTip>
<Grid Background="Transparent" HorizontalAlignment="Right" Height="12" Margin="1,-4,-4,0" VerticalAlignment="Top" Width="12">
<Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C" Margin="1,3,0,0"/>
<Path Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff" Margin="1,3,0,0"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="TextBox" BasedOn="{StaticResource BaseTextBoxStyle}"/>

最佳答案

据我所知,这是 TextBox 的一个错误。控制。根据 this question ,如果您分配相同的 SolidColorBrushCaretBrush和其他东西(比如 Foreground )然后你的 Foreground会闪烁 CaretBrush !所以看起来TextBox弄乱了你的画笔。

解决方法是确保每个文本框都有一个单独的 SolidColorBrush CaretBrush 的实例.这有点痛苦,但这是我能找到的最佳解决方案。例如:

<Color x:Key="CaretColor">White</Color>

<TextBox>
<TextBox.CaretBrush>
<SolidColorBrush Color="{StaticResource CaretColor}" />
</TextBox.CaretBrush>
</TextBox>

如果您想要更高效的语法,可以使用标记扩展:
public class BrushFactoryExtension : MarkupExtension
{
public BrushFactoryExtension()
{ }

public BrushFactoryExtension(Color color)
{
Color = color;
}

public Color Color { get; set; }

public override object ProvideValue(IServiceProvider serviceProvider)
{
return new SolidColorBrush(Color);
}
}

然后,对于 XAML 中的每个文本框:
<TextBox CaretBrush="{local:BrushFactory Color={StaticResource CaretColor}" />

关于silverlight-4.0 - Silverlight 样式使插入符号消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7385943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com