![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 > |
| | #3 (permalink) |
| 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 news D773884-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> > |
| |
| |
![]() |
| 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 |