选择时为列表框指定垂直对齐方式 //WP7 C# XAML
当选择列表框项目时,我希望所选项目在点击时垂直居中。我希望将其添加到我的 c# 中。这就是我到目前为止所得到的。我希望将相同的内容应用于我的辅助列表框项目(listBox1 和 listBox2)。
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//MessageBox.Show("Item selected: " + listBox1.SelectedItem.ToString());
if (listBox1.SelectedIndex == 3)
{
listBox2.ScrollIntoView(listBox2.Items[27]);
}
}
private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//MessageBox.Show("Item selected: " + listBox2.SelectedItem.ToString());
}
When a list box item is selected, I would like for the selected item to become vertically centered on hit. I was hoping to add this to my c#. This is what I've got so far. I want the same to be applied to my secondary list box item (listBox1 AND listBox2).
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//MessageBox.Show("Item selected: " + listBox1.SelectedItem.ToString());
if (listBox1.SelectedIndex == 3)
{
listBox2.ScrollIntoView(listBox2.Items[27]);
}
}
private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//MessageBox.Show("Item selected: " + listBox2.SelectedItem.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想更改不同状态下某些内容的外观,我建议使用 VisualStateManager 并在相关状态下相应地更改元素的属性。在
ListBox
的项目实例中,您可能应该更改ItemContainerStyle
。If you want to change the appearance of something in different states I'd reccomend using the
VisualStateManager
and changing properties of the elements accordingly in the relevant state. In the instance of the items for yourListBox
, you should probably change theItemContainerStyle
.