Reputation: 28586
Is there a way to put a Border
on the Grid
without surrounding the Grid
with the Border
element?
<Border Margin="{Binding ElementName=thisUserControl, Path=PrintMargin}"
BorderThickness="{Binding ElementName=thisUserControl,
Path=PrintMarginThickness}"
BorderBrush="LightGray">
<Grid x:Name="mainGrid"
Background="{Binding ElementName=thisUserControl, Path=Background}" />
</Border>
Could I use something like "BitmapEffect" on the grid or stuff like this? I just need to display or not a border named "PrintMargin" on my WpfUserControl...
This border should or not be visible and also perhaps I need to control its Thickness and maybe Color(Brush)...
Upvotes: 0
Views: 3338
Reputation: 2564
Well I did this for a Button
a few weeks ago, maybe you can adapt the sample to the Grid
control?
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="5"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
EDIT: I guess you'll have to use the Panel
approach instead of the ContentPresenter
, not sure how to do it from there, but hopefully this is somewhat helpful.
Upvotes: 1
Reputation: 8455
Don't see anything wrong with doing the way you mentioned (border around the grid), but if you really want you can add Border
as a last element in your Grid
:
<Grid>
.. other elements ..
<Border BorderBrush="DeepPink" BorderThickness="1" />
</Grid>
Upvotes: 2