wpf 목록 상자와 두 개의 단추 (위아래)가 있습니다.가로 방향 목록 상자에서 데이터 이동
사용자가 목록에서 임의의 항목을 선택하고 아래로 버튼을 클릭하면 다음 항목 (선택한 항목 포함)이 모두 아래쪽으로 이동해야합니다. 그리고 마찬가지로, 위로 버튼을 클릭하면 위로 움직여야합니다.
예가 아래에 설명되어있다 : - 사용자가 학생 2 제 학기 항목을 선택하고, 다운 버튼을 클릭하면, 위의 표에
Student 1 Student 2 Student 3
Sem 1 1 1
Physics 68 87 70
Chemistry 78 89 78
Math 62 77 80
Sem 2 2 2
Physics 78 69 78
Chemistry 58 79 88
Math 72 67 90
아래와 같이 학생 2에 대한 데이터는 아래로 이동한다 -
Student 1 Student 2 Student 3
Sem 1 1
Physics 68 70
Chemistry 78 78
Math 62 80
Sem 2 1 2
Physics 78 87 78
Chemistry 58 89 88
Math 72 77 90
이동 된 데이터는 검색 가능해야합니다. observable 컬렉션을 사용하여 목록 상자의 itemsource를 바인딩하고 있습니다. 아래는 내 샘플 코드입니다 : -
<Window.Resources>
<DataTemplate x:Key="myTemplate">
<StackPanel>
<Label Background="Purple" Foreground="White" BorderBrush="Red" BorderThickness="4">
<Label.Content>
<WrapPanel HorizontalAlignment="Stretch">
<TextBlock>Student Name:</TextBlock>
<TextBlock Text="{Binding Name}" />
</WrapPanel>
</Label.Content>
</Label>
<WrapPanel>
<ListBox ItemsSource="{Binding LstSubjects}" BorderThickness="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0">
<TextBlock> Sem:</TextBlock>
<TextBlock Text="{Binding Semester}"></TextBlock>
</WrapPanel>
<WrapPanel Grid.Row="1">
<TextBlock> Physics:</TextBlock>
<TextBlock Text="{Binding Physics}"></TextBlock>
</WrapPanel>
<WrapPanel Grid.Row="2">
<TextBlock> Chemistry:</TextBlock>
<TextBlock Text="{Binding Chemistry}"></TextBlock>
</WrapPanel>
<WrapPanel Grid.Row="3">
<TextBlock> Maths:</TextBlock>
<TextBlock Text="{Binding Maths}"></TextBlock>
</WrapPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding StudentModel}" ItemTemplate="{StaticResource myTemplate}" Margin="0,0,0,0" VerticalAlignment="Top">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
목록 상자가 학생 이름과 모든 주제 마크 (SEM, 물리, 화학, 수학)의 목록이 포함되어 있습니다.
미리 감사드립니다.
것 같습니다. 이를 위해 itemtemplate을 만들고 각 행에 정렬 할 수 있습니다. 데이터를 위로 이동하는 것은 매우 드문 일입니다. 기본적으로 나는 당신의 테이블 배열을 개선 할 수 있다고 생각합니다. – deafjeff
@deafjeff : 답변 해 주셔서 감사합니다. 네 말이 맞아, 나는 각 학생을 위해 여러 가지 상품 묶음을 관리해야 해. 내가이 유스 케이스에 정말로 걸려 있기 때문에 약간의 sapmle 코드를 공유해 주시겠습니까? –