如何设置网格中的列在有空间时自动收缩?
我的 Windows Phone 7.5 应用程序中有以下列表框。基本上,列表框的 ItemTemplate 包含一个图像、一些文本,然后是一个图像。
如果我将一张或两张图像的“可见性”属性设置为“折叠”,我希望文本列展开至其最大尺寸(而不是换行文本),例如占用图像先前占用的空间。相反,当我将图像的“可见性”设置回“可见”时,我希望图像出现并且文本收缩。
我怎样才能在 Xaml 中完成类似的事情?
<ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" >
<ListBox.Resources>
<BitmapImage x:Key="ProjectIcon" UriSource="Images/Dark/appbar.delete.rest.png" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="58"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="58"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{StaticResource ProjectIcon}" Visibility="Collapsed" Width="48" Height="48" />
<StackPanel Grid.Column="1" Margin="0,0,0,17" Width="432" Height="78" Orientation="Vertical">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
<Image Grid.Column="2" Source="{StaticResource ProjectIcon}" Visibility="Visible" Width="48" Height="48" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have the following Listbox in my Windows Phone 7.5 app. Basically the ItemTemplate for the listbox contains an image, some text, then an image.
If I set the Visibility property on one or both images to Collapsed, I'd like the text column to expand to its maximum size (rather than wrap text), e.g. take up the space that was previously taken up by images. Conversely, when I set the Visility of the images back to Visible, I'd like the images to appear and the text to contract.
How can I pull off something like that in Xaml?
<ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" >
<ListBox.Resources>
<BitmapImage x:Key="ProjectIcon" UriSource="Images/Dark/appbar.delete.rest.png" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="58"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="58"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{StaticResource ProjectIcon}" Visibility="Collapsed" Width="48" Height="48" />
<StackPanel Grid.Column="1" Margin="0,0,0,17" Width="432" Height="78" Orientation="Vertical">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
<Image Grid.Column="2" Source="{StaticResource ProjectIcon}" Visibility="Visible" Width="48" Height="48" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将第 0 列和第 2 列的宽度都设置为“自动”,并将 MaxWidth 设置为 58 怎么样?
How about setting the Width of both column 0 and 2 to Auto, and give them a MaxWidth of 58?