项目中所有表单的文本框样式 [英] textbox styling for all the forms in the project
本文介绍了项目中所有表单的文本框样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的一个表单(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>
推荐答案
此问题无法解答一两行。解释这些事情不仅仅需要一篇文章。所以这篇文章将帮助您入门并指出正确的方向。
WPF:使用样式和控制模板自定义应用程序(第1部分,共2部分) [ ^ ]
来自MSDN的示例
https:// msdn.microsoft.com/en-us/library/aa970773.aspx [ ^ ]
进一步阅读:
https://msdn.microsoft.com/en-us/library/ms745683(v = vs.110)的.aspx [ ^ ]
https://msdn.microsoft.com/en-us/library/ee230084(v = vs.110).aspx [ ^ ]
This question cannot be answered in a line or two. It will take more than an article to explain the things. So here is a article that will get you started and point in the right direction.
WPF: Customize your Application with Styles and Control Templates (Part 1 of 2)[^]
Examples from MSDN
https://msdn.microsoft.com/en-us/library/aa970773.aspx[^]
Further Reading:
https://msdn.microsoft.com/en-us/library/ms745683(v=vs.110).aspx[^]
https://msdn.microsoft.com/en-us/library/ee230084(v=vs.110).aspx[^]
这篇关于项目中所有表单的文本框样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文