我有一个itemscontrol,但是,这些项目与左边对齐,我无法弄清楚如何水平拉伸它们。
这是我的XAML:
<ItemsControl x:Name="ItemsSnaps" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="ButtonSnap" HorizontalAlignment="Stretch" Style="{StaticResource EmptyItemSourceAction}" Tag="{Binding}"
toolkit:TiltEffect.IsTiltEnabled="{Binding Converter={StaticResource IValueCheckIfSnapWasRecieved}}"
Click="ButtonSnap_Click"
ManipulationCompleted="ButtonSnap_ManipulationCompleted"
ManipulationStarted="ButtonSnap_ManipulationStarted">
<Grid Tag="{Binding}" Height="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding Converter={StaticResource IValueIconFromSnapMediaType}}" Margin="10" Stretch="UniformToFill" />
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="#FF616161" Text="{Binding FallbackValue=alexerax, Converter={StaticResource IValueActiveUserFromSnap}}" FontSize="18.667"></TextBlock>
<TextBlock Foreground="#FF616161" FontSize="18.667" Text="-" Margin="5,0,5,0" />
<TextBlock Foreground="#FF616161" FontSize="18.667" TextTrimming="WordEllipsis" Text="{Binding Path=Timestamp, FallbackValue=18/08/94 - 14:34, Converter={StaticResource IValueFriendlyTimeFromSnapChatTimestamp}}" />
</StackPanel>
<TextBlock FontSize="13.333" Text="{Binding FallbackValue=Pending..., Converter={StaticResource IValueFriendlySnapStatus}}">
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource FapAccent}"/>
</TextBlock.Foreground>
</TextBlock>
<ProgressBar Width="150" Visibility="{Binding Converter={StaticResource IValueCheckIfSnapIsDownloading}}" HorizontalAlignment="Stretch" IsIndeterminate="True"></ProgressBar>
</StackPanel>
<ContentControl VerticalAlignment="Center" Grid.Column="2">
<TextBlock Text="10" >
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource FapAccent}"/>
</TextBlock.Foreground>
</TextBlock>
</ContentControl>
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
答案 0 :(得分:1)
你能否使用基于%tage的grid.columns来对齐它们?第2列中的10s具有坚硬的Ypx宽度,以1 * px
的柱状结构放置EG:
<Grid Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <!-- scale to fit rest -->
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="1">
<!-- main stuff-->
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="2">
<!-- right orientated text [10s] -->
</StackPanel>
</Grid>
答案 1 :(得分:0)
所以,问题在于我的样式是将HorizontalAlignment
设置为Left
的空按钮。 VS的大小调整使得代码的一部分离开屏幕,所以我看向它正好。