xaml - How do I properly draw and scale a Canvas as a WPF background to a control? -


i have stackpanel needs contain drawn background. specifically, stackpanel needs have ability grow , rectangle must grow stackpanel, must remain pseudo-anchored each side @ fixed position.

i've attempted use canvas.left, canvas.right, canvas.top , canvas.bottom attached properties, far they've not worked. furthermore, seem work when drawing within canvas objects, not when embedded within visualbrush set background. how can accomplish drawing resizable, rectangular background within stackpanel?

below state of current code. i've tried various approaches none seem work.

my code:

<stackpanel dockpanel.dock="right" orientation="vertical" verticalalignment="center">     <stackpanel.background>         <visualbrush stretch="none">             <visualbrush.visual>                  <canvas background="magenta" horizontalalignment="stretch" verticalalignment="stretch">                     rectangle fill="#ffddecf7" canvas.left="20" canvas.top="20" canvas.bottom="20" canvas.right="0"/>                 </canvas>             </visualbrush.visual>         </visualbrush>     </stackpanel.background>     ... </stackpanel> 

this doesn't render anything. set canvas background magenta see if drawing, , i'm not seeing that. other attempts have drawn canvase, however, blue rectangle stretched fill window, regardless of attached canvas property settings.

sample:

the image below sample of want. again, i'm using ugly magenta color show offset of internal, blue rectangle. stackpanel grows or shrinks, rectangle needs affixed top, left, right , bottom.

enter image description here

my suggestion place stackpanel inside grid:

<grid dockpanel.dock="right" verticalalignment="center" background="magenta">     <rectangle margin="20" fill="#ffddecf7"/>     <stackpanel orientation="vertical">         no background...     </stackpanel>  </grid> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -