我正在使用停靠面板来显示从 itemsource 读取并希望水平显示它们但它垂直显示它们的按钮列表。
我正在使用以下代码:
<DockPanel Name="DockPanel2" Grid.Row="1" Visibility="Visible">
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="260,50,0,0">
<ItemsControl ItemsSource="{Binding PageViewModels}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Foreground="MidnightBlue"
Content="{Binding Name}" Command="{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CommandParameter="{Binding }"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<ContentControl Content="{Binding CurrentPageViewModel}"/>
</DockPanel>
如果我使用以下代码(将按钮作为静态列表,我可以以水平方式显示列表。
<DockPanel Name="DockPanel2" Grid.Row="1" Visibility="Visible">
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="260,50,0,0">
<Button Content="Button 1" Margin="2" />
<Button Content="Button 2" Margin="2" />
<Button Content="Button 3" Margin="2" />
<Button Content="Button 4" Margin="2" />
<Button Content="Button 5" Margin="2" />
</StackPanel>
<ContentControl Content="{Binding CurrentPageViewModel}" />
</DockPanel>
有人可以告诉我哪里出错了。
谢谢,