Sorry I was not very clear. I'll rephrase.
Where do I put the Text="{Binding Title}" (that was in my DataTemplate) if I
am using an ItemContainerStyle?
<Style x:Key="PageListBoxItem" TargetType="ListBoxItem">
<Setter Property="Foreground" Value="#FF000000" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="RootElement" Background="{TemplateBinding
Background}">
<Rectangle x:Name="FocusVisualElement" Stroke="Black"
StrokeDashArray="1,2" Visibility="Collapsed" />
<ContentPresenter
Content="{Binding Title}"
ContentTemplate="{TemplateBinding ContentTemplate}"
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The above code is my Style in Resources section. I've cut out most of the
content apart from a few tags just to give you an idea. I'm actually using
the whole default style with the idea to customise it. (taken from
http://msdn.microsoft.com/en-us/library/cc278062(VS.95).aspx ). The only
line I've changed is the Content= line.
It did not seem like the right thing to do as everything else is referring
to the TemplateBindings. I thought there might be a way to set it locally on
the ListBox(Item) rather than in the resource section.
Or maybe you can have an ItemContainerStyle and a ItemContainer both at the
same time? I'll try that... ohhhh... ok, I think I can see my problem. I was
confusing my ControlTemplate with my DataTemplate. I've just put back the
DataTemplate and I think I understand it now.
So correct me if I am wrong, I can set the style of the ItemContainerStyle
and control what the ListBoxItem looks like, and at the same time, I can
also set the ItemTemplate (putting a DataTemplate in it) and style how the
data IN the ListBoxItem is presented. Perhaps I should not be applying
styles to the UIElements in the DataTemplate and rather do that in the
ItemContainerStyle?
I'll also have a read of the link that Valentin posted.
Thanks for the replies. :)
Stephen
On Wed, May 14, 2008 at 3:54 PM, Andrea Boschin <[EMAIL PROTECTED]> wrote:
> On Wed, May 14, 2008 at 9:45 AM, Stephen Price <[EMAIL PROTECTED]>
> wrote:
>
> > Hey all,
> >
> > I have a question on Databindings.
> >
> Your question is not really clear. I think you have assigned the
> DataTemplate to the wrong property (ItemContainerStyle). This property has
> to be used to give a <Style> to the item container. You have to assign the
> data template to the same ItemTemplate property.
>
> <ListBox x:Name="pageList" SelectionChanged="pageList_SelectionChanged"
> ItemTemplate="{StaticResource PageListBoxItem}" />
>
> But I'm not sure about your question... Is PageListBoxItem the
> DataTemplate you have put in the Resources section?
> If I didn't understand please post a little more code.
>
> Bye
>
> --
> Andrea Boschin
> Microsoft(R) MVP - [Visual Developer - ASP/ASP.NET]
> http://blog.boschin.it
> http://www.xedotnet.org
> http://mvp.support.microsoft.com/profile/Andrea.Boschin
> -------------------------------------------------------------------
> OzSilverlight.com - to unsubscribe from this list, send a message back to
> the list with 'unsubscribe' as the subject.
> Powered by mailenable.com - List managed by www.readify.net
-------------------------------------------------------------------
OzSilverlight.com - to unsubscribe from this list, send a message back to the
list with 'unsubscribe' as the subject.
Powered by mailenable.com - List managed by www.readify.net