带有扩展器的列表框到另一个列表框
Listbox with Expanders to another listbox
我正在尝试从列表框中的扩展器中移动项目(将项目保留在那里)并将其复制到另一个列表框。
<ListBox Name="lbAvailableColumns" Grid.Row="1" Grid.Column="0">
<Expander Header="Account" Background="Transparent" BorderBrush="{x:Null}" >
<StackPanel>
<ListBox>
<ListBoxItem Content="Account Is Locked Out"/>
<ListBoxItem Content="Expiration Date"/>
<ListBoxItem Content="Last Lockout Date"/>
<ListBoxItem Content="Must Change Password"/>
<ListBoxItem Content="Password Age(Days)"/>
<ListBoxItem Content="Password Last Changed"/>
<ListBoxItem Content="Password Never Expires"/>
<ListBoxItem Content="Password Not Required"/>
<ListBoxItem Content="Smart Card Required For Logon"/>
<ListBoxItem Content="User Cannot Change Password"/>
<ListBoxItem Content="Username"/>
</ListBox>
</StackPanel>
</Expander>
<Expander Header="Exchange" Background="Transparent" BorderBrush="{x:Null}" />
<Expander Header="General" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Group Membership" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Organization" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Other" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Profile" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="System" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Telephone" Background="Transparent" BorderBrush="{x:Null}"/>
</ListBox>
我正在尝试执行以下操作,但遇到了一些麻烦。
正在尝试将扩展列表框中的项目复制到可见列列表框中。有什么想法吗?
我写过其中一个,但没有分组到扩展器中。如果你做对了,分组是一个附带问题。
你想要做的是给你的视图模型一些数据项 class 的两个 ObservableCollection
,比如说 FromItems
和 ToItems
。将 XAML 中的这两个集合绑定到两个 ListBoxes
的 ItemsSource
属性。
数据项 class 可以是一个非常简单的快速 class,具有两个属性(不是字段):比方说,Name
和 GroupName
,都是字符串。按 GroupName
分组。 Here's a group template expander answer, here's how to do the actual grouping 并在每个 ListBox
上设置 DisplayMemberPath="Name"
。
>
按钮从 FromItems
中删除左侧列表框的 SelectedItem
,并将其添加到 ToItems
。 <
按钮则相反。您可能不想从 FromItems
中删除,但您必须小心不要将它们添加到 ToItems
两次。
根据 @Ed Plunkett 的建议,我编写了一个完整的示例。
上的源代码
我正在尝试从列表框中的扩展器中移动项目(将项目保留在那里)并将其复制到另一个列表框。
<ListBox Name="lbAvailableColumns" Grid.Row="1" Grid.Column="0">
<Expander Header="Account" Background="Transparent" BorderBrush="{x:Null}" >
<StackPanel>
<ListBox>
<ListBoxItem Content="Account Is Locked Out"/>
<ListBoxItem Content="Expiration Date"/>
<ListBoxItem Content="Last Lockout Date"/>
<ListBoxItem Content="Must Change Password"/>
<ListBoxItem Content="Password Age(Days)"/>
<ListBoxItem Content="Password Last Changed"/>
<ListBoxItem Content="Password Never Expires"/>
<ListBoxItem Content="Password Not Required"/>
<ListBoxItem Content="Smart Card Required For Logon"/>
<ListBoxItem Content="User Cannot Change Password"/>
<ListBoxItem Content="Username"/>
</ListBox>
</StackPanel>
</Expander>
<Expander Header="Exchange" Background="Transparent" BorderBrush="{x:Null}" />
<Expander Header="General" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Group Membership" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Organization" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Other" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Profile" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="System" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Telephone" Background="Transparent" BorderBrush="{x:Null}"/>
</ListBox>
我正在尝试执行以下操作,但遇到了一些麻烦。
正在尝试将扩展列表框中的项目复制到可见列列表框中。有什么想法吗?
我写过其中一个,但没有分组到扩展器中。如果你做对了,分组是一个附带问题。
你想要做的是给你的视图模型一些数据项 class 的两个 ObservableCollection
,比如说 FromItems
和 ToItems
。将 XAML 中的这两个集合绑定到两个 ListBoxes
的 ItemsSource
属性。
数据项 class 可以是一个非常简单的快速 class,具有两个属性(不是字段):比方说,Name
和 GroupName
,都是字符串。按 GroupName
分组。 Here's a group template expander answer, here's how to do the actual grouping 并在每个 ListBox
上设置 DisplayMemberPath="Name"
。
>
按钮从 FromItems
中删除左侧列表框的 SelectedItem
,并将其添加到 ToItems
。 <
按钮则相反。您可能不想从 FromItems
中删除,但您必须小心不要将它们添加到 ToItems
两次。
根据 @Ed Plunkett 的建议,我编写了一个完整的示例。