DataTemplate을 통해 Button으로 두 개의 WrapPanel을 채우고 있습니다. 그러나 어떤 이유로 든 세로로 정렬되어 있습니다. 왜 여기 정확히 잘못 되었습니까? Orientation 속성을 설정했는지 여부는 중요하지 않습니다.WrapPanel이 DataTemplate에서 가로로 줄 바꿈하지 않습니다.
XAML : 이것은 WrapPanel의 모습입니다
<UserControl x:Class="DashboardClient.View.DashboardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Width="940" Height="640">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}},Path=ActualHeight}">
<ScrollViewer VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top" Height="520" Margin="5">
<WrapPanel>
<ItemsControl ItemsSource="{Binding Dashboards}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Width="120" Height="120" Margin="5" Command="{Binding DataContext.DashboardCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}">
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" Text="{Binding Name}" />
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Width="120" Height="120" Margin="5" Command="{Binding DashboardAddCommand}" Content="+" FontSize="100" />
</WrapPanel>
</ScrollViewer>
<StackPanel Height="100" Margin="5">
<Label>Dashboardname:</Label>
<TextBox Text="{Binding SelectedDashboard.Name}" />
<RadioButton Content="Sichtbar" Margin="0 10" IsChecked="{Binding SelectedDashboard.IsVisibleOnDashboard, UpdateSourceTrigger=PropertyChanged}" />
<Button Content="Dashboard löschen" Command="{Binding DashboardRemoveCommand}" />
</StackPanel>
</DockPanel>
<StackPanel Grid.Column="1" Margin="0">
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}},Path=ActualHeight}">
<WrapPanel>
<ItemsControl ItemsSource="{Binding SelectedDashboard.DashboardItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Width="200" Height="120" Command="{Binding DataContext.DashboardItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" Margin="10">
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" Text="{Binding Name}" />
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Width="200" Height="120" Content="+" FontSize="100" Command="{Binding DashboardItemAddCommand}" Margin="10" />
</WrapPanel>
</ScrollViewer>
</StackPanel>
</Grid>
</UserControl>
:
이
추가 버튼은 항상 너무, 어떻게 든 잘립니다. 당신이 WrapPanel에 수평으로 ItemsControl에의 자식을 넣어하려는 경우
'WrapPanel'은 아이들의 아이들을 정렬하지 않습니다. 귀하의 코드에서 그것은 단지 2 명의 자식들, 즉 ItemsControl과 add-'Button을 처리합니다. 쉽게 해결할 수 있을지 잘 모르겠습니다. 'ScrollViewer' 위에 추가 -Button' 부동을 만들었으므로 언제든지 그것을 누를 수 있습니다. 대시 보드를 추가해야하는 경우 목록 끝까지 계속 스크롤하십시오. – Sinatr
ItemsCntrol은 기본적으로 StackPanel이며 따라서 문제가 있다고 생각합니다. ItemsControl의 패널을 WrapPanel로 변경하십시오. https://stackoverflow.com/questions/3131919/wrappanel-as-itempanel-for-itemscontrol – kenny
스크롤 뷰어에서이 내용도 참조하십시오. https://stackoverflow.com/a/2028583/3225 – kenny