![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | 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 > |
My System Specs![]() |
| | #3 (permalink) |
| | 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> > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Setting up a Word template with fixed fields | Microsoft Office | |||
| Vista Won't Let Me Create XP-Style Directory Tree for Old Template Files | Vista file management | |||
| Font Size - XP style vs Vista style | Vista General | |||