Articles → WPF → Creating your first control template in WPF

Creating your first control template in WPF











<TextBox Width="150" Height="25"></TextBox>




<TextBox Width="150" Height="25" Style="{StaticResource TextBoxStyle}"></TextBox>




<Grid.Resources>
	<Style TargetType="TextBox" x:Key="TextBoxStyle"></Style>
</Grid.Resources>






<Style TargetType="TextBox" x:Key="TextBoxStyle">
	<Setter Property="Template">
		<Setter.Value>
			<ControlTemplate></ControlTemplate>
		</Setter.Value>
	</Setter>
</Style>






<Style TargetType="{x:Type TextBox}" x:Key="TextBoxStyle">
	<Setter Property="Template">
		<Setter.Value>
			<ControlTemplate>
				<Border CornerRadius="1" BorderThickness="0.5" BorderBrush="Black">
					<Grid>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto"></ColumnDefinition>
							<ColumnDefinition Width="*"></ColumnDefinition>
						</Grid.ColumnDefinitions>
						<Image Source="images\Emoticon.gif" HorizontalAlignment="Left" Grid.Column="0"></Image>
						<TextBox BorderThickness="0" Margin="0,0,1,0" HorizontalAlignment="Stretch" BorderBrush="Transparent" Grid.Column="1" VerticalContentAlignment="Center"></TextBox>
					</Grid>
				</Border>
			</ControlTemplate>
		</Setter.Value>
	</Setter>
</Style>





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, April 04, 2010

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250