Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > WPF и Silverlight > Стиль на TextBox с тригером


Автор: Bladerender 22.9.2012, 00:42
Пытаюсь добиться, что бы когда TextBox ставал IsEnable=False - принимал тот стиль, который я хочу
Не могу понять, что делаю не так. 
Код

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="Rout.Task"
    x:Name="UserControl" Height="24.333" Width="300">
    <UserControl.Resources>
        <Style x:Key="ControlStyle1" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Background" Value="{x:Null}"/>
                    <Setter Property="BorderBrush" Value="{x:Null}"/>
                    <Setter Property="Foreground" Value="Silver"/>
                    <Setter Property="CaretBrush" Value="#FFDADADA"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Margin="0">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF3F3F3F" Offset="0"/>
                <GradientStop Color="#FF3B3B3B" Offset="1"/>
                <GradientStop Color="#FF1B1B1B" Offset="0.524"/>
            </LinearGradientBrush>
        </Grid.Background>
        <TextBox x:Name="u_TODO_Text" Margin="16.995,1.666,45.452,2.666" TextWrapping="Wrap" Text="TextBox" Height="20" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Silver" CaretBrush="#FFDADADA" Style="{StaticResource ControlStyle1}"/>
    </Grid>
</UserControl>

Автор: Bladerender 23.9.2012, 11:41
НУ помогите

Попробовал отак. Стиль применяется, но я так понимаю, что базовый темплейт вообще переопределяется на мой, и текст вообще никак не видно, хотя в базовом темплейте цвет текста серый

Код

<Style x:Key="myTextBox" TargetType="{x:Type TextBox}">  
             <Setter Property="Template">  
                <Setter.Value> 
                <ControlTemplate TargetType="{x:Type TextBox}">  
                         <ControlTemplate.Triggers> 
                            <Trigger Property="IsEnabled" Value="False">  
                                <Setter Property="Background" Value="{x:Null}"/>
                             <Setter Property="BorderBrush" Value="{x:Null}"/>
                             <Setter Property="Foreground" Value="Silver"/>
                             <Setter Property="CaretBrush" Value="#FFDADADA"/>
                            </Trigger> 
                        </ControlTemplate.Triggers> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 

Автор: exBlender 24.9.2012, 21:39
Код
<Style x:Key="{x:Type TextBoxBase}" BasedOn="{x:Null}" TargetType="{x:Type TextBoxBase}">
        <Setter Property="FontSize" Value="" />
        <Setter Property="Foreground" Value="" />
        <Setter Property="Background" Value="" />
        <Setter Property="BorderBrush" Value="" />
        <Setter Property="BorderThickness" Value="" />
        <Setter Property="CaretBrush" Value="" />
        <Setter Property="Margin" Value="" />
        <Setter Property="Padding" Value="" />
        <Setter Property="AllowDrop" Value="true" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="ContextMenu" Value="{StaticResource TextBoxContextMenu}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBoxBase}">
                    <Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}>
                        <ScrollViewer x:Name="PART_ContentHost"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" Value="" />
                            <Setter Property="BorderBrush" Value="" />
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Background" Value="" />
                        </Trigger>
                        <Trigger Property="IsReadOnly" Value="True">
                            <Setter Property="Background" Value="" />
                            <Setter Property="BorderBrush" Value="" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBoxBase}}" />

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)