c# - 文本框 Silverlight 的样式

标签 c# silverlight xaml templates

我想为文本框制作一个简单的样式。我想保留关于的一切 除一项外的标准文本框外观。

OnFocus on 希望能够改变文本框的边框颜色。

我写了以下内容,它确实有效。但是,一切都重新设计了,我必须 声明高度,非焦点边框的外观和感觉也不同。如何创建模板以仅影响焦点状态。

 <Style x:Key="TextBoxStyle" TargetType="TextBox">

            <Setter Property="BorderBrush" Value="Gold" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Grid Height="{TemplateBinding Height}"

                             >
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver" />
                                    <VisualState x:Name="Pressed" />
                                    <VisualState x:Name="Disabled" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="brd" 
                                                            Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" 
                                                            Duration="0" 
                                                            To="Red" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="brd" 
                                    BorderBrush="{TemplateBinding BorderBrush}" 
                                    BorderThickness="{TemplateBinding BorderThickness}" 
                                    Background="{TemplateBinding Background}"
                                    CornerRadius="2">
                                <ContentPresenter x:Name="contentPresenter" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

最佳答案

您需要复制原始 TextBox 的整个模板,您可以找到 here .然后进行所需的更改。

关于c# - 文本框 Silverlight 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3353627/

相关文章:

c# - Silverlight DataGrid 中的多行单元格

silverlight - 启用/禁用数据网格中的行(MVVM 模式)

c# - Xaml - 如何使用 ViewModel 中的 ImageSource

wpf - 使用自定义类型扩展名指定DataTemplate.DataType

c# - 在组标题 WPF 中显示 "filled"行的数量

c# - 如何使用 C# 创建 SQL Server 2012 数据库?

c# - 检查鼠标左键按下的时间

c# - TD 不能嵌套在 TABLE 中

silverlight - 在Silverlight编程中,如何防止访问者缓存下载的内容?

silverlight - 在 Silverlight 中将 FontWeight 绑定(bind)到 bool 值