Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Tue, 25 Sep 2007 23:05:44 +0200,    group: microsoft.public.windows.developer.winfx.avalon        back       


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 ?)
date: Tue, 25 Sep 2007 23:05:44 +0200   author:   Eager am

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:
> 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
date: Thu, 27 Sep 2007 11:36:59 +0200   author:   Laurent Bugnion, MVP

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"  wrote in message 
news:usDj1nOAIHA.1204@TK2MSFTNGP03.phx.gbl...
> 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:
>> 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
date: Thu, 27 Sep 2007 17:12:30 +0200   author:   Eager am

Re: CustomControl and controlTemplate   
Hi,

Eager wrote:
> 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).

:-) I think that if you try to compare XAML to C#, you're going to have 
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
date: Fri, 28 Sep 2007 09:06:46 +0200   author:   Laurent Bugnion, MVP

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us