where does controltemplate code go?

M

mp

dumb newb question
reading article on control template
start new project, add wpf window,
don't know where to paste the control template snippet
<ControlTemplate x:Key="MyListBoxTemplate" TargetType="{x:Type ListBox}">

<Border Background="White" BorderBrush="Black"

BorderThickness="1" CornerRadius="6">

<ScrollViewer Margin="4">

<ItemsPresenter />

</ScrollViewer>

</Border>

</ControlTemplate>





the empty window code (when add wpf window to project) is:

<Window x:Class="WpfApplication1.Window2"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Window2" Height="300" Width="300">

<Grid>


</Grid>


</Window>



i cant' find anywhere inside that code block to paste the control code that
doesn't produce compiler errors.

thanks

mark
 
M

mp

Peter Duniho said:
What article?


http://drwpf.com/blog/2009/05/12/itemscontrol-l-is-for-lookless/


Why does the article not have its own code examples to

i probably just need to read more times, the explanation is probably there
soemwhere

start new project, add wpf window,
don't know where to paste the control template snippet
<ControlTemplate x:Key="MyListBoxTemplate" TargetType="{x:Type ListBox}">
[...]
</ControlTemplate>

the empty window code (when add wpf window to project) is:

<Window x:Class="WpfApplication1.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Grid>
</Grid>
</Window>



i cant' find anywhere inside that code block to paste the control code
that doesn't produce compiler errors.

You can put it anywhere that a ControlTemplate object is valid. For
example, the Template property of a Control object. Note that the Window
class inherits the Control class. Note also that the ControlTemplate
you've posted here is specifically applied to a ListBox object, so it
stands to reason that the object you'd actually want to assign it to would
be in fact a ListBox object. Your Window definition doesn't appear to
include one of those at the moment.

Pete

I thought i could put it anywhere in the window definition and then any
control could use it
i'll keep reading
thanks
mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top