handycontrol的TextBox的占位符,默认是白色的背景,黑色的字。如果黑色的背景,白色的字,就比较麻烦,尝试了很久,终于搞定了。
下面是样式:
<Style
x:Key="SmallHcTextBoxStyle"
BasedOn="{StaticResource {x:Type hc:TextBox}}"
TargetType="{x:Type hc:TextBox}">
<Setter Property="Height" Value="30" />
<Setter Property="FontSize" Value="{DynamicResource SmallFontSize}" />
<Setter Property="Foreground" Value="{DynamicResource ForeGround}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="CaretBrush" Value="{DynamicResource ForeGround}" />
<Setter Property="Background" Value="{DynamicResource LinearGradientBrushForTextBoxForComboBox}" />
<Setter Property="BorderBrush" Value="{DynamicResource CheckButtonBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:TextBox">
<Grid>
<!-- 背景和普通文本 -->
<Border
x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="3.5"
SnapsToDevicePixels="True">
<ScrollViewer
x:Name="PART_ContentHost"
Margin="4,0,4,0"
Focusable="False" />
</Border>
<TextBlock
Margin="4,0,4,0"
VerticalAlignment="Center"
Foreground="{DynamicResource ForeGround}"
IsHitTestVisible="False"
Text="{Binding Path=(hc:InfoElement.Placeholder), RelativeSource={RelativeSource TemplatedParent}}"
Visibility="{TemplateBinding Text,
Converter={StaticResource String2VisibilityReConverter}}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource BackGroundActive}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource BackGroundActive}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
调用:
<hc:TextBox
Name="PositionResult"
Grid.Row="1"
Margin="0,0,3,0"
HorizontalAlignment="Stretch"
hc:InfoElement.Placeholder="其他部位"
Style="{StaticResource SmallHcTextBoxStyle}"
TextChanged="PositionResult_OnTextChanged" />
1975

被折叠的 条评论
为什么被折叠?



