locked
AdornerDecorator in Stylesheet RRS feed

  • Question

  • Validation Errors disappear inside tabcontrol

    Hi..from the above link i put all my textboxes in AdornerDecorator for a page and it is working fine...
    but i got so many pages,so i thought to to place this in a stylesheet which im using
    for all textboxes common.

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

    can anyone say is there any way around to put this in this style..

    or do we need to put AdornerDecorator in all the pages
    • Edited by Issac999 Wednesday, April 25, 2012 5:21 AM
    Wednesday, April 25, 2012 5:20 AM

Answers

  • Hi Isaac,

    Please have a look at code snippet below for ur concern.

    XAML:
    
    <Window x:Class="SandBox.Window67"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window67" Height="300" Width="300">
        <Grid>
            <Grid.Resources>
                <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
                    <Setter Property="SnapsToDevicePixels" Value="True"/>
                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="MinWidth" Value="20"/>
                    <Setter Property="MinHeight" Value="20"/>
                    <Setter Property="Margin"  Value="5"/>
                    <Setter Property="FontSize" Value="11"/>
                    <Setter Property="AllowDrop" Value="true"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                                <AdornerDecorator>
                                    <Border 
                Name="Border"
                CornerRadius="2" 
                Padding="2"
                Background="Red"
                BorderBrush="Blue"
                BorderThickness="1" >
                                        <ScrollViewer Margin="0" x:Name="PART_ContentHost" VerticalAlignment="Center"/>
                                    </Border>
                                </AdornerDecorator>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBox x:Name="txt" Grid.Row="0" Height="25" Width="100"></TextBox>
        </Grid>
    </Window>
    

    Please mark it as an answer if it resolves ur issue.

    Regards, Parth Shah

    • Proposed as answer by parth.shah Wednesday, April 25, 2012 6:08 AM
    • Marked as answer by Issac999 Thursday, April 26, 2012 4:44 AM
    Wednesday, April 25, 2012 6:08 AM

All replies

  • Hi Isaac,

    U can define the custom control template for ur textbox wherein u can define AdornerDecorator over each textbox.

    Hope it helps!


    Regards, Parth Shah

    Wednesday, April 25, 2012 5:56 AM
  • Hi Isaac,

    Please have a look at code snippet below for ur concern.

    XAML:
    
    <Window x:Class="SandBox.Window67"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window67" Height="300" Width="300">
        <Grid>
            <Grid.Resources>
                <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
                    <Setter Property="SnapsToDevicePixels" Value="True"/>
                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="MinWidth" Value="20"/>
                    <Setter Property="MinHeight" Value="20"/>
                    <Setter Property="Margin"  Value="5"/>
                    <Setter Property="FontSize" Value="11"/>
                    <Setter Property="AllowDrop" Value="true"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                                <AdornerDecorator>
                                    <Border 
                Name="Border"
                CornerRadius="2" 
                Padding="2"
                Background="Red"
                BorderBrush="Blue"
                BorderThickness="1" >
                                        <ScrollViewer Margin="0" x:Name="PART_ContentHost" VerticalAlignment="Center"/>
                                    </Border>
                                </AdornerDecorator>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBox x:Name="txt" Grid.Row="0" Height="25" Width="100"></TextBox>
        </Grid>
    </Window>
    

    Please mark it as an answer if it resolves ur issue.

    Regards, Parth Shah

    • Proposed as answer by parth.shah Wednesday, April 25, 2012 6:08 AM
    • Marked as answer by Issac999 Thursday, April 26, 2012 4:44 AM
    Wednesday, April 25, 2012 6:08 AM