views:

147

answers:

2

I want to add the border off canvas using C# not XAML

How can i achieve it?

+1  A: 

You can simple create border canvas with DataBinding on her Width to MainCanvas.ActualWidth and Height to MainCanvas.ActualHeight

Svisstack
A: 

I think you're better off by placing the canvas inside a border, then specify the border thickness in your codebehide. In your code you could then programmatically turn the border on and off.

XAML:

<Border x:Name="CanvasBorder" BorderBrush="Black">
    <Canvas>
        <!--Items here-->
    </Canvas>
</Border>

Codebehide:

// Turn on border
CanvasBorder.BorderThickness = new Thickness(1);

// Turn off border
CanvasBorder.BorderThickness = new Thickness(0);
Brent