因为某些原因,使用 dataTemplate 添加的项不会按照我的要求执行操作!!
我试图在 StackPanel 中水平地放置多个图像,但无论我如何尝试,它们都只会垂直排列。
以下是我的 XAML 代码:
<DataTemplate x:Name="View">
<Border BorderBrush="Red" BorderThickness="4" >
<StackPanel Orientation="Horizontal">
<ItemsControl ItemsSource="{Binding Path=_Collection, Mode=OneWay}" >
<ItemsControl.ItemTemplate>
<DataTemplate >
<Image Source="{Binding _Source}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Height="30" FontFamily="Trebuchet MS" FontSize="18" Text="{Binding _Name}" />
</StackPanel>
</Border>
</DataTemplate>
一切都绑定好了。这是从用户控件内部调用的。
<ItemsControl ItemTemplate="{StaticResource siteView}" ItemsSource="{Binding Path=_SiteDisplay"/>
我的可观察集合“_SiteDisplay”包含另一个可观察集合“_Collection”,它保存了图像的url。
这是从实际代码中简化出来的,但说明了问题。我无法使图像水平对齐!非常感谢任何帮助或更好的解决方法的建议。