本文介绍了项目中所有表单的文本框样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的一个表单(window1.xaml)中的文本框的代码,我已经为文本框应用了Textbox.style,我的要求是我想为我项目中的所有文本框应用同样的样式所有窗口(window2.xaml,window3.xaml,.........)
Here is the code for the Textbox in one of my form(window1.xaml) here i have applied Textbox.style for the textbox, My requirement is i want to apply this same style for all the textboxes in my project all windows(window2.xaml,window3.xaml,.........)
<textbox grid.column="0" maxlength="1000" x:name="txtQuestionDesc" horizontalalignment="Stretch" textwrapping="Wrap" acceptsreturn="True" xmlns:x="#unknown">
Grid.Row="1"
Margin="5,0,0,5" Height="100"
Text="{Binding QuestionText, UpdateSourceTrigger=LostFocus}" >
<textbox.style>
<Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style.Resources>
<visualbrush x:key="CueBannerBrush" alignmentx="Left" alignmenty="Center" stretch="None">
<visualbrush.visual>
<Label Content="Question Description" Foreground="LightGray" HorizontalAlignment="Center" />
</visualbrush.visual>
</visualbrush>
</Style.Resources>
<Style.Triggers>
<trigger property="Text" value="{x:Static sys:String.Empty}">
<setter property="Background" value="{StaticResource CueBannerBrush}" />
</trigger>
<trigger property="Text" value="{x:Null}">
<setter property="Background" value="{StaticResource CueBannerBrush}" />
</trigger>
<trigger property="IsKeyboardFocused" value="True">
<setter property="Background" value="White" />
</trigger>
</Style.Triggers>
</Style>
</textbox.style>
</textbox>
推荐答案
这篇关于项目中所有表单的文本框样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!