1. 程式人生 > 其它 >WPFTextBox控制元件顯示水印

WPFTextBox控制元件顯示水印

WPFTextBox控制元件顯示水印效果

<TextBox x:Name="TbxInput" Grid.Row="1" Width="320" Height="25" Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Center" Text="{Binding SelectInfo,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                            <TextBox.Resources>
                                <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
                                    <VisualBrush.Visual>
                                        <TextBlock FontStyle="Normal" Text="工藝編碼、工藝名稱" />
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </TextBox.Resources>
                            <TextBox.Style>
                                <Style TargetType="TextBox">
                                    <Style.Triggers>
                                        <Trigger Property="Text" Value="{x:Null}">
                                            <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                        </Trigger>
                                        <Trigger Property="Text" Value="">
                                            <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>
                            <TextBox.InputBindings>
                                <KeyBinding Key="Enter" Command="{Binding CmdSelectProcessItem}" ></KeyBinding>
                            </TextBox.InputBindings>
                        </TextBox>