gpt4 book ai didi

Silverlight - 将 Listbox ActualWidth 绑定(bind)到 ListboxItem 宽度

转载 作者:行者123 更新时间:2023-12-02 05:13:08 24 4
gpt4 key购买 nike

我正在为 Windows Phone 7 创建一个照片库,我试图让每张图片全屏显示并水平滑动。到目前为止我正在做的是使用我修改过的列表框来水平滚动,但问题是我似乎无法找到一种方法将 ListboxItem 的宽度和高度与列表框的 ActualWidth 和 ActualHeight 绑定(bind)本身。我想这样做的原因是,如果手机的方向发生变化,照片的大小也会发生变化以适应屏幕。

以下是我目前得到的代码(我试过使用 TemplatedParent 和 RelativeSource 但我一定是做错了什么,因为它根本不起作用):

<Style x:Key="PhotoGalleryItem" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="ListBoxItemRoot" HorizontalAlignment="Stretch" Margin="4,0,4,0" Width="{Binding RelativeSource={RelativeSource TemplatedParent},Path=ActualWidth}">
<Image Source="{Binding Mode=OneWay}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="controls:PhotoGallery">
<Setter Property="Background" Value="Red"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:PhotoGallery">
<Border BorderBrush="Transparent" BorderThickness="0" >
<Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="Scroller" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" >
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle" Value="{StaticResource PhotoGalleryItem}" />
</Style>

关于如何实现这个结果有什么想法吗?

谢谢

最佳答案

这可能类似于这个问题I asked before

 Add HorizontalContentAlignment="Stretch" to your ListBox. 
That should do the trick.

我看到你已经用 setter 设置了“HCA”,所以我不确定到底发生了什么。

关于Silverlight - 将 Listbox ActualWidth 绑定(bind)到 ListboxItem 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3646243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com