【问题标题】:textbox styling for all the forms in the project项目中所有表单的文本框样式
【发布时间】:2015-08-11 08:07:43
【问题描述】:

这是我的表单之一(window1.xaml)中文本框的代码,我已经为文本框应用了 Textbox.style,我的要求是我想为我的项目中的所有文本框应用相同的样式所有窗口(window2.xaml,window3.xaml,......)

<TextBox Grid.Column="0" MaxLength="1000" x:Name="txtQuestionDesc" HorizontalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True"
             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 xaml mvvm


【解决方案1】:

在您的 App.xaml 上添加样式,它应该可以工作

【讨论】:

  • 自定义控件是什么意思?如果您在 App.xaml 中定义它,它将应用于应用程序中的每个文本框,除非您为文本框定义了另一种样式
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-16
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
相关资源
最近更新 更多