![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | CustomControl and controlTemplate I want to write a custom control which has a (dependency ?) property which is an enum type, e.g. enum:. public enum LookKindOfMyCustomControl { TwoRectanglesAndALine, TwoEllipsesAndARectangle, ThreeEllipsesAndTwoRectangles } (Just an example, the idea is that each of the items in the enumerator list represents composite shapes, GeometryGroups, PathGeometry or similar which is not easily represented as a parameterized "thing"). How can I best present this with a default style/template for the custom control ? By setting a particular ControlTemplate based on change of the property ? How would the syntax be ? Better done in code ? (but what about if an application wants to override the look of the control ?) |
My System Specs![]() |
| | #2 (permalink) |
| | Re: CustomControl and controlTemplate Hi, It's relatively easy to do if you use a Style trigger. For example (out of the top of my head) <Control.Style> <Style TargetType="{x:Type Control}"> <Setter Property="Template"> <Setter.Value> <!--Do something--> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding MyLookAndFeel}" Value="TwoRectanglesAndALine"> <Setter Property="Template"> <Setter.Value> <!--Do something--> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding MyLookAndFeel}" Value="TwoEllipsesAndARectangle"> <Setter Property="Template"> <Setter.Value> <!--Do something--> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding MyLookAndFeel}" Value="ThreeEllipsesAndTwoRectangles"> <Setter Property="Template"> <Setter.Value> <!--Do something--> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </Control.Style> To know if your property (which I named here MyLookAndFeel) must be a DependencyProperty, you must know if the value may change during runtime. If it's a DP, a change during runtime will be applied to the control. If it's a normal (CLR) property, the value will be loaded when the control is loaded, but subsequent changes will not be applied. Greetings, Laurent Eager wrote: Quote: > I want to write a custom control which has a (dependency ?) property > which is an enum type, e.g. enum:. > > public enum LookKindOfMyCustomControl > { > TwoRectanglesAndALine, > TwoEllipsesAndARectangle, > ThreeEllipsesAndTwoRectangles > } > > (Just an example, the idea is that each of the items in the enumerator > list represents composite shapes, GeometryGroups, PathGeometry or > similar which is not easily represented as a parameterized "thing"). > > How can I best present this with a default style/template for the custom > control ? > By setting a particular ControlTemplate based on change of the property > ? How would the syntax be ? > Better done in code ? (but what about if an application wants to > override the look of the control ?) Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft.ch PhotoAlbum: http://www.galasoft.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| | #3 (permalink) |
| | Re: CustomControl and controlTemplate Thanks a lot Laurent I guess this means that XAML does not have something similar to a switch statement (C#), but only if statements which will all be executed (the trigger elements). "Laurent Bugnion, MVP" <galasoft-lb@xxxxxx> wrote in message news:usDj1nOAIHA.1204@xxxxxx Quote: > Hi, > > It's relatively easy to do if you use a Style trigger. For example (out of > the top of my head) > > <Control.Style> > > <Style TargetType="{x:Type Control}"> > > <Setter Property="Template"> > <Setter.Value> > <!--Do something--> > </Setter.Value> > </Setter> > > <Style.Triggers> > <DataTrigger Binding="{Binding MyLookAndFeel}" > Value="TwoRectanglesAndALine"> > <Setter Property="Template"> > <Setter.Value> > <!--Do something--> > </Setter.Value> > </Setter> > </DataTrigger> > <DataTrigger Binding="{Binding MyLookAndFeel}" > Value="TwoEllipsesAndARectangle"> > <Setter Property="Template"> > <Setter.Value> > <!--Do something--> > </Setter.Value> > </Setter> > </DataTrigger> > <DataTrigger Binding="{Binding MyLookAndFeel}" > Value="ThreeEllipsesAndTwoRectangles"> > <Setter Property="Template"> > <Setter.Value> > <!--Do something--> > </Setter.Value> > </Setter> > </DataTrigger> > </Style.Triggers> > > </Style> > > </Control.Style> > > To know if your property (which I named here MyLookAndFeel) must be a > DependencyProperty, you must know if the value may change during runtime. > If it's a DP, a change during runtime will be applied to the control. If > it's a normal (CLR) property, the value will be loaded when the control is > loaded, but subsequent changes will not be applied. > > Greetings, > Laurent > > > Eager wrote: Quote: >> I want to write a custom control which has a (dependency ?) property >> which is an enum type, e.g. enum:. >> >> public enum LookKindOfMyCustomControl >> { >> TwoRectanglesAndALine, >> TwoEllipsesAndARectangle, >> ThreeEllipsesAndTwoRectangles >> } >> >> (Just an example, the idea is that each of the items in the enumerator >> list represents composite shapes, GeometryGroups, PathGeometry or similar >> which is not easily represented as a parameterized "thing"). >> >> How can I best present this with a default style/template for the custom >> control ? >> By setting a particular ControlTemplate based on change of the property ? >> How would the syntax be ? >> Better done in code ? (but what about if an application wants to override >> the look of the control ?) > -- > Laurent Bugnion [MVP ASP.NET] > Software engineering, Blog: http://www.galasoft.ch > PhotoAlbum: http://www.galasoft.ch/pictures > Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |
| | #4 (permalink) |
| | Re: CustomControl and controlTemplate Hi, Eager wrote: Quote: > Thanks a lot Laurent > > I guess this means that XAML does not have something similar to a switch > statement (C#), but only if statements which will all be executed (the > trigger elements). long, sleepless nights. It's really a very different paradigm. That said, you're right, in the sense that the triggers will all be evaluated, but in that particular case, only one will be applied. Greetings! Laurent -- Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft.ch PhotoAlbum: http://www.galasoft.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
My System Specs![]() |