Skip to main content

Microsoft Silverlight

Answered Question Templating/styling of gridsRSS Feed

(0)

MFriis
MFriis

Member

Member

1 points

7 Posts

Templating/styling of grids

 Hey guys

Rookie at SL here. Im starting to look at templating and styling to make a more reusable design. Styling is going along just fine but im having problems templating bigger chunks of design. I tried looking at the Diggs Sample but it seems the templating there only works on buttons. Something which seems to be quite normal in tutorials on the net (they all revolve around buttons)

  I have the following grid which with some retangles gets a nice round, glasslike appearance with a shadow.

1    <Grid Width="355" Height="65" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="15,15,0,0">
2                <Rectangle RadiusX="10" RadiusY="10" Fill="#22000000" Margin="0,4,0,0" />
3                <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="#7700A303" Margin="0,0,0,6" />
4                <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15"  />
5                <StackPanel Canvas.Left="20" Canvas.Top="14" Margin="20,14,10,0">
6                    <TextBlock x:Name="TitleTextBlock" 
7                        HorizontalAlignment="Left" VerticalAlignment="Center" Text="SilverRoute" TextWrapping="Wrap" FontWeight="Bold" />
8                    <TextBlock x:Name="DescriptorTextBlock" 
9                        HorizontalAlignment="Left" VerticalAlignment="Center" Text="Løberute planlægningsværktøj" TextWrapping="Wrap" FontWeight="Bold" />
10               </StackPanel>
11           </Grid>

  I have successfully moved the styling of the rectangles into each of their own style. But what i really want to do is make a Grid template in which i can put panels (like the stackpanel here) and it will just surround it with the design effect.

i tried making the following style combined with a template based on the diggs sample

 
1           <Style x:Key="StyllishGrid" TargetType="Grid">
2                <Setter Property="Template">
3                    <Setter.Value>
4                        <ControlTemplate>
5                            <Rectangle RadiusX="10" RadiusY="10" Fill="#22000000" Margin="0,4,0,0" />
6                            <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="#7700A303" Margin="0,0,0,6" />
7                            <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15"  />
8                        </ControlTemplate>
9                    </Setter.Value>
10               </Setter
11           

 But with zero success.

 

What is the aproach here? Theres a striking absense of tutorials on this subject :)

bharathkumars87
bharathk...

Member

Member

280 points

51 Posts

Re: Templating/styling of grids

 hai fiss,

    I have not understand ur question, i Think u want shadow effect this the code..

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid .Effect>
                                    <DropShadowEffect/>
                                </Grid .Effect>

-----here u can add ur control-------

</Grid>

 

 

bharath kumar.s
Please "Mark as Answer" if this post answered your question. :)

MFriis
MFriis

Member

Member

1 points

7 Posts

Re: Re: Templating/styling of grids

 Im not sure i can be any more specific in  detailing the problem.

 It has nothing to do with adding a shadow effect. 

 

Im trying to add elements to a style i can use several places. Something which seems to only work for elements like a button. Not a grid.

bharathkumars87
bharathk...

Member

Member

280 points

51 Posts

Re: Re: Re: Templating/styling of grids

 I think u want to add style for controls, i am right

Style="{StaticResource InPlaceEditTextBox}"

try this

bharath kumar.s
Please "Mark as Answer" if this post answered your question. :)

Todd Herman
Todd Herman

Member

Member

616 points

116 Posts

Re: Templating/styling of grids

What you are trying, with the Grid, isn't really going to work.  When you create a template, you are creating a new look (and sometimes feel) of an existing control.  The Grid has no look (basically) and your template isn't changing anything, it is creating something new.  It seems more like that you want to create a custom control or a user control.  Either of which creates a reusable control (or set of controls) with a specific look and feel.  Just take your first sample (the Grid with the Rectangles) and put it inside a UserControl.  Then you can reuse that as often as you need/want to.

 

 

If this post answered your question, please mark as answered.

Todd Herman
http://blogs.thecodearchitects.com

Min-Hong Tang - MSFT
Min-Hong...

Contributor

Contributor

3376 points

377 Posts

Answered Question

Re: Templating/styling of grids

Hi,

    Templating only works for control which has a template, or you can create your own template control(like asp.net's custom control somehow).

   As to control with out a template , you can use them to build user controls.

  Here is a good article you can check it out after you are done with Diggs Sample , it helps you to build your own templated control.

 http://msdn.microsoft.com/en-us/magazine/cc721611.aspx 

  You will get a more profound view of silverlight's controls after building your own control.

Best Regards  

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities