Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,.........)

HTML
<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}" &gt;
                    <textbox.style>
                        &lt;Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt;
                            &lt;Style.Resources&gt;
                                <visualbrush x:key="CueBannerBrush" alignmentx="Left" alignmenty="Center" stretch="None">
                                    <visualbrush.visual>
                                        &lt;Label Content="Question Description" Foreground="LightGray" HorizontalAlignment="Center" /&gt;
                                    </visualbrush.visual>
                                </visualbrush>
                            &lt;/Style.Resources&gt;
                            &lt;Style.Triggers&gt;
                                <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>
                            &lt;/Style.Triggers&gt;
                        &lt;/Style&gt;
                    </textbox.style>
                </textbox>
Posted
Updated 28-May-15 11:05am
v3
Comments
[no name] 28-May-15 16:55pm    
The search term you are looking for is "resource dictionary"

1 solution

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[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-May-15 17:06pm    
Nice, a 5.
—SA
Mathi Mani 28-May-15 17:13pm    
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900