Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I've created a Custom Control named "ecDateBox" derived by a TextBox. I want a ToggleButton, that has an Image, to appear inside at the right border of the TextBox. This is the ResourceDictionary:

XML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:emmbeeControls">

	<local:CalendarConverter x:Key="calendarConverter"/>

	<ControlTemplate x:Key="IconButton" TargetType="{x:Type ToggleButton}">
		<Border>
			<ContentPresenter/>
		</Border>
	</ControlTemplate>

	<Style TargetType="{x:Type local:ecDateBox}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:ecDateBox}">
					<Grid>
						<Border
							removed="{TemplateBinding Background}"
							BorderThickness="{TemplateBinding BorderThickness}"
							BorderBrush="{TemplateBinding BorderBrush}"
							ClipToBounds="True"
							CornerRadius="5"
							Padding="2">
							<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
						</Border>
						<ToggleButton Template="{StaticResource IconButton}"
							Focusable="False"
							IsChecked="False"
							Margin="-1,0,0,0" 
							MaxHeight="{TemplateBinding Height}" Width="20"
							Name="CalendarPopUpButton">
							<Image Name="CalendarImage"
								HorizontalAlignment="Right"
								Source="Images/Calendar.png"
								Stretch="Uniform"
								Visibility="Visible">
							</Image>
						</ToggleButton>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>


In MainWindow.xaml I use the Custom Control with a simple

XML
<ecDateBox/>


The Custom Control ecDateBox will be rendered, but there is no ToggleButton in it.
If I remove
XML
Template="{StaticResource IconButton}"
near the Tag
XML
<ToggleButton...
the ToggleButton appears in the Control, but has no Image.

What's wrong with that code?

Thanks in advance.
Michael
Posted
Comments
LLLLGGGG 18-Jun-15 12:04pm    
Try to add these properties to the ContentPresenter in the iconButton template:
HorizontalAlignment="center" VerticalAlignment="center" and try doing the same with stretch. And try to remove that MaxHeight and just set the Height property.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900