c# - How to make a StackPanel fit its Children's width -


i'm writing down here because i'm having lots of issues thing, , hope able me out :p

i want create dynamic stackpanel fits children's width. i'll make example.

let's stackpanel empty. width 10 (f.e.) , fixed height 30. want add image, , wrote down:

bitmapimage myimage = new bitmapimage(new uri("[path]")); image realimage = new image(); realimage.source = myimage; realimage.width = 50; realimage.height = myimage.height; mystackpanel.children.add(realimage); 

the stackpanel not enlarge 50px though; it's stuck 10px, cutting image. same happens when try add other ui elements, textblocks , on.

i tried like

mystackpanel.width += realimage.width; 

but of course didn't work. i've tried set stackpanel's width "auto", didn't either. stackpanel declaration in xaml:

<window x:name="mainwindow1" x:class="proj.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mytitle" height="480" width="640"     loaded="onload" background="black" minheight="480" minwidth="640">     <grid>         ...(other closed tags)...         <stackpanel orientation="horizontal" name="mystackpanel" height="30" margin="135,283,458,147"/>     </grid> </window> 

i need stackpanel because have show dynamic bar variable number of objects perform marquee effect on screen, sliding right left. don't know neither number of objects nor final width of dynamic bar.

of course, if know there other way it, i'll glad learn :)

thank you!

put stackpanel scrollviewer , set width auto:

    <scrollviewer horizontalscrollbarvisibility="auto">         <stackpanel  width="auto">             ....         </stackpanel>     </scrollviewer> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -