开发者

How to automatically collapse a Grid Column in xaml?

开发者 https://www.devze.com 2023-04-12 01:28 出处:网络
Basically I\'m getting some data from a service and displaying the results in a listbox. The template for the items is using a grid. NOTE: If there is a better way let me know.

Basically I'm getting some data from a service and displaying the results in a listbox. The template for the items is using a grid. NOTE: If there is a better way let me know.

<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition/>
       <ColumnDefinition/>
   </Grid.ColumnDefinitions>
   <Image Grid.Column="0"/>
   <TextBlock Grid.Column="1"/>
&开发者_开发问答lt;/Grid>

The problem is, that sometimes an image is not returned. In that case the column for the image should collapse and the text column should take up the full width.

How to automatically collapse a Grid Column in xaml?

I've tried a couple of different ways already with no luck. How can I collapse this column when no image is returned?


<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="Auto"/>
       <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>
   <Image Grid.Column="0"/>
   <TextBlock Grid.Column="1"/>
</Grid>

Setting the image column width to auto will resize the column width according to the image size. If there is no image the size will be set to 0. The text column is set to *, this way it always takes all the available space.

Note: If your images are big, you may need to set MaxWidth as well.


You can use Expander control and set IsExpanded property.

0

精彩评论

暂无评论...
验证码 换一张
取 消