views:

1002

answers:

3

Is there an easy way to give rounded corners to the boundary of a DataGrid in Silverlight 3?

Thanks a bunch!

A: 
<Border CornerRadius="5">
    <toolkit:DataGrid />
</Border>
qntmfred
A: 

Hi there, try this one:

<Border.Background>
  <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
     <GradientStop Color="Black" Offset="0"/>
     <GradientStop Color="#FF508EB1" Offset="1"/>
  </LinearGradientBrush>
</Border.Background>

<Grid Background="{x:Null}"  x:Name="MainGrid" >
<Grid.Effect>
  <DropShadowEffect />
</Grid.Effect>

    <...>
</Grid>
</Border>
elsharpo
Sorry if this is a dumb qn, but is the above modifying the default template for a DataGrid?
Silver Gun
I tried this one. It simply gave it a gradient border, and yet no rounded corners. FAIL
Silver Gun
+4  A: 

I just answered a similar question here for giving rounded corners to any FrameworkElement by attaching a Blend clipping behavior with a specified CornerRadius.

You could write your own logic for the clipping behavior or use the one from the Expression Blend Samples CodePlex page. It would then be as simple referencing System.Windows.Interactivity.dll from the Blend SDK and dropping the behavior on the element in Blend or writing out the XAML:

<data:DataGrid>
    <i:Interaction.Behaviors>
        <samples:ClippingBehavior CornerRadius="15"/>
    </i:Interaction.Behaviors>
</data:DataGrid>

Its a nice reusable way to give rounded corners to any element without relying on a border or an element with corner radii properties.

Dan Auclair
I'll definitely try this. However, I did use Tim Heuer's solution which was similar to this (but did not use Behaviors), and there was a problem with that. When i launched my solution, the corners would not be rounded. Then I would restore the window size, and then Maximize it, and the corners would then show up as rounded. I hope the same does not happen with this.
Silver Gun