Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Setting up collections in a style/template

Closed Thread
 
Thread Tools Display Modes
Old 06-10-2007   #1 (permalink)
David Cater
Guest


 

Setting up collections in a style/template

This is a styling question. I would like to create a style that fills a
collection in the target object with certain values. For example, if I
created a class called FruitStand, I might want to have a property on
FruitStand called TypesOfFruit. I would then like to be able to create a
style that looks like:

<Style TargetType={x:Type local:FruitStand}>
<Setter Property="TypesOfFruit">
<Setter.Value>
<local:Fruit>apple</local:Fruit>
<local:Fruit>pear</local:Fruit>
<local:Fruit>banana</local:Fruit>
</Setter.Value>
</Setter>
</Style>

Because TypesOfFruit isn't a Dependency Property I'm not allowed to do that.
And I'm not sure what the appropriate structure would be for making a
collection a DependencyProperty.

I've tried to find some existing WPF element that exhibits this kind of
behavior so I could look in Reflector to see how the framework supports it.
So far I haven't found any examples. "Collections" like RenderTransform and
BitmapEffects are actually scalar properties that allow you to specify a
single child that itself contains the collection (TransformGroup,
BitmapEffectGroup).

I thought Grid.ColumnDefinitions might be a good example, because I would
have thought that you would be able to style a Grid with a set of
ColumnDefinitions and RowDefinitions. But I tried doing that
unsuccessfully, and I haven't found any examples online showing how to
create a style for a Grid that would accomplish that. I found one reference
from 2005 indicating that "Templates don't have complete support for
collection properties". I'm hoping that comment is out of date.

Any thoughts?

Thanks,

David Cater

Old 06-11-2007   #2 (permalink)
Andrew Whiddett \(Home\)
Guest


 

Re: Setting up collections in a style/template

Use FreezableCollection...

"David Cater" <xiard@mindspring.com> wrote in message
news:89136478-F717-4E5F-8B4D-7B48D9585852@microsoft.com...
> This is a styling question. I would like to create a style that fills a
> collection in the target object with certain values. For example, if I
> created a class called FruitStand, I might want to have a property on
> FruitStand called TypesOfFruit. I would then like to be able to create a
> style that looks like:
>
> <Style TargetType={x:Type local:FruitStand}>
> <Setter Property="TypesOfFruit">
> <Setter.Value>
> <local:Fruit>apple</local:Fruit>
> <local:Fruit>pear</local:Fruit>
> <local:Fruit>banana</local:Fruit>
> </Setter.Value>
> </Setter>
> </Style>
>
> Because TypesOfFruit isn't a Dependency Property I'm not allowed to do
> that. And I'm not sure what the appropriate structure would be for making
> a collection a DependencyProperty.
>
> I've tried to find some existing WPF element that exhibits this kind of
> behavior so I could look in Reflector to see how the framework supports
> it. So far I haven't found any examples. "Collections" like
> RenderTransform and BitmapEffects are actually scalar properties that
> allow you to specify a single child that itself contains the collection
> (TransformGroup, BitmapEffectGroup).
>
> I thought Grid.ColumnDefinitions might be a good example, because I would
> have thought that you would be able to style a Grid with a set of
> ColumnDefinitions and RowDefinitions. But I tried doing that
> unsuccessfully, and I haven't found any examples online showing how to
> create a style for a Grid that would accomplish that. I found one
> reference from 2005 indicating that "Templates don't have complete support
> for collection properties". I'm hoping that comment is out of date.
>
> Any thoughts?
>
> Thanks,
>
> David Cater
>


Old 06-11-2007   #3 (permalink)
David Cater
Guest


 

Re: Setting up collections in a style/template

Thanks for the info on FreezableCollection; I wasn't aware of that class.

Here's what I did. I have a class called NewsReader. I added the following
lines to the class:

private FreezableCollection<ExposedProperty> m_ExposedProperties =
new FreezableCollection<ExposedProperty>();
public FreezableCollection<ExposedProperty> ExposedProperties { get
{ return m_ExposedProperties; } }

That allowed me to do the following in XAML:

<avc:NewsReader.ExposedProperties>
<avc:ExposedProperty PropertyName="RefreshFrequency" Access="ReadOnly"
/>
<avc:ExposedProperty PropertyName="FeedUrls" Access="Writeable" />
</avc:NewsReader.ExposedProperties>

However, when I tried to do the following in a Style:

<Setter Property="ExposedProperties">
<Setter.Value>
<avc:ExposedProperty PropertyName="RefreshFrequency"
Access="ReadOnly" />
<avc:ExposedProperty PropertyName="FeedUrls" Access="Writeable" />
</Setter.Value>
</Setter>

I get the error:

"Property Setter 'ExposedProperties' cannot be set because it does not have
an accessible set accessor."

I don't want to add a Set accessor for ExposedProperties itself, because the
FreezableCollection itself isn't being set; I'm just trying to add elements
to it. What am I missing here?

Thanks,

David

"Andrew Whiddett (Home)" <awhiddett@lpcast.com> wrote in message
newsD773884-E94F-4BCA-8ABD-318AF4E08438@microsoft.com...
> Use FreezableCollection...
>
> "David Cater" <xiard@mindspring.com> wrote in message
> news:89136478-F717-4E5F-8B4D-7B48D9585852@microsoft.com...
>> This is a styling question. I would like to create a style that fills a
>> collection in the target object with certain values. For example, if I
>> created a class called FruitStand, I might want to have a property on
>> FruitStand called TypesOfFruit. I would then like to be able to create a
>> style that looks like:
>>

<snip>
>


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista Won't Let Me Create XP-Style Directory Tree for Old Template Files Michael Wyland Vista file management 6 06-12-2008 03:18 PM
Font Size - XP style vs Vista style John M. Dlugosz Vista General 0 02-24-2008 12:46 AM
Font Size - XP style vs Vista style John M. Dlugosz Vista General 0 02-19-2008 06:48 PM
Why setting triggers on a ControlTemplate works but not on a style? Philippe Lavoie Avalon 2 08-09-2006 10:54 AM
How to navigate through ListBox items via a style/template? Pascal Bourque Avalon 0 01-31-2006 04:47 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50