私はwpfリストボックスと2つのボタン(上下)を持っています。水平方向のリストボックスでのデータ移動
ユーザーがリスト内の任意の項目を選択して下ボタンをクリックすると、次の項目(選択項目を含む)はすべて下方向にシフトする必要があります。同様に、上のボタンをクリックすると上に移動します。
例が以下に説明されている: - ユーザが学生2ための第1学期の項目を選択してボタンダウンをクリックした場合、上記の表に
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、物理学、化学、数学)のリストが含まれていることに注意してください。
ありがとうございます。
あなたが "SEM /物理学/化学/数学" の項目-バンドルを管理するように見えます。そのためのitemtemplateを作成し、それを各行に配置することができます。データを上に移動することは非常に珍しいことです。基本的には、あなたのテーブルの配置が改善されていると思います。 – deafjeff
@deafjeff:あなたの答えをありがとう。あなたは正しいです、私は各学生のためにいくつかの商品バンドルを管理する必要があります。私は本当にこのユースケースに固執しているので、いくつかのsapmleコードを共有してください。 –