C#中c listbox 添加中怎样在鼠标选定后添加项

Silverlight和Metro中ListBox样式的添加及使用
今天在做Windwos Metro开发词典时,遇到如何在FlipView 左右移动时,更改ListBox的选中项。XAML代码如下所示: FlipViewGrid.Row= 1 x:Name= ViewDicResult FontSize= 34 ItemsSource= {BindingDicList} FlipView.ItemsPanel ItemsPanelTemplate VirtualizingStackPanelOrientation= Horizontal / /ItemsPanelTem
    今天在做Windwos Metro开发词典时,遇到如何在FlipView 左右移动时,更改ListBox的选中项。XAML代码如下所示:
&FlipView&Grid.Row=&1&&x:Name=&ViewDicResult&&FontSize=&34&&ItemsSource=&{Binding&DicList}&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&FlipView.ItemsPanel&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ItemsPanelTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VirtualizingStackPanel&Orientation=&Horizontal&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ItemsPanelTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/FlipView.ItemsPanel&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&FlipView.ItemTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DataTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Grid&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ScrollViewer&&Height=&{Binding&ElementName=ViewDicResult}&&Content=&{Binding&Panel}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Grid&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/DataTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/FlipView.ItemTemplate&
&&&&/FlipView&&
  该代码主要用于显示每一本词典的解释内容,当我们在触摸屏上左右滑动时,FlipView控件里的Items项会跟着左右滑动,显示不同的内容;我们将FlipView控件Item的改变绑定到ListBox上,当我们向左或向右滑动时,ListBox的选中项也会跟着改变。ListBox的代码如下所示:
&&ListBox&x:Name=&SubDicName&&&Background=&Transparent&&Margin=&0&&&Height=&75&&HorizontalAlignment=&Center&&VerticalAlignment=&Bottom&&ItemsSource=&{Binding&DicList}&&&SelectedItem=&{Binding&SelectedItem,&ElementName=ViewDicResult,&Mode=TwoWay}&&IsTabStop=&False&&&Style=&{StaticResource&SubDicListBoxStyle}&&&ItemContainerStyle=&{StaticResource&SubDicListBoxItemStyle}&&&/&
  注意以上红色代码,两个控件绑定的是同一数据源,ListBox的SelectedItem绑定到FlipView控件,绑定的模式为双向绑定,这样不管哪一个控件改变,都会引发另一个控件的数据改变。这里不介绍具体的实现。主要是ListBox的样式如何设置。
  ListBox有一个ItemContainerStyle属性,该属性主要是定义每一个Item的显示样式,这个ItemTemplate属性有点不一样,ItemContainerStyle主要是设计,每一项的状态,比如在CommonStates(通常状态),SelectionStates(选中状态)显示的效果。
  以下的Style主要实现了ListBox在选中时的样式,鼠标放上去时,以及鼠标左键按下去,鼠标左键弹起来时以及选中项的效果的样式。
&Style&x:Key=&SubDicListBoxItemStyle&&TargetType=&ListBoxItem&&
&&&&&&&&&Setter&Property=&Background&&Value=&Transparent&/&
&&&&&&&&&Setter&Property=&TabNavigation&&Value=&Local&/&
&&&&&&&&&Setter&Property=&Padding&&Value=&8,10&/&
&&&&&&&&&Setter&Property=&HorizontalContentAlignment&&Value=&Left&/&
&&&&&&&&&Setter&Property=&Template&&
&&&&&&&&&&&&&Setter.Value&
&&&&&&&&&&&&&&&&&ControlTemplate&TargetType=&ListBoxItem&&
&&&&&&&&&&&&&&&&&&&&&Border&x:Name=&LayoutRoot&&BorderBrush=&{TemplateBinding&BorderBrush}&&BorderThickness=&{TemplateBinding&BorderThickness}&&Background=&{TemplateBinding&Background}&&
&&&&&&&&&&&&&&&&&&&&&&&&&VisualStateManager.VisualStateGroups&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualStateGroup&x:Name=&CommonStates&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Normal&&&&//通常状态时Item的状态,选中项的矩形框高度只有4像素
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DoubleAnimationUsingKeyFrames&EnableDependentAnimation=&True&&Storyboard.TargetProperty=&(FrameworkElement.Height)&&Storyboard.TargetName=&rectangle&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0&&Value=&4&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/DoubleAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&PointerOver&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--鼠标放上去时Item的背景颜色--&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemPointerOverForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Disabled&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Background&&Storyboard.TargetName=&LayoutRoot&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&Transparent&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemDisabledForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Pressed&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--按下鼠标时Item的背景颜色--&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemPressedForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualStateGroup&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualStateGroup&x:Name=&SelectionStates&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Unselected&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--改变选中项后,原来被选中的项的动画--&//当从一个Item改变到另个一个Item时,原来被选中的Item会执行此动画
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DoubleAnimationUsingKeyFrames&EnableDependentAnimation=&True&&Storyboard.TargetProperty=&(FrameworkElement.Height)&&Storyboard.TargetName=&rectangle&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0&&Value=&16&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0:0:0.5&&Value=&4&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/DoubleAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Selected&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Background&&Storyboard.TargetName=&InnerGrid&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&Transparent&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemSelectedForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&SelectedUnfocused&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--选中时Item的背景色--&&&&//当Item被选中时,会执行此动画(矩形框的高度会从4像素变成16像素)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DoubleAnimationUsingKeyFrames&EnableDependentAnimation=&True&&Storyboard.TargetProperty=&(FrameworkElement.Height)&&Storyboard.TargetName=&rectangle&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0&&Value=&4&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0:0:0.5&&Value=&16&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/DoubleAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemSelectedForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&SelectedDisabled&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Background&&Storyboard.TargetName=&InnerGrid&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&Transparent&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemSelectedDisabledForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&SelectedPointerOver&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--鼠标左键弹起时Item的背景颜色--&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DoubleAnimationUsingKeyFrames&EnableDependentAnimation=&True&&Storyboard.TargetProperty=&(FrameworkElement.Height)&&Storyboard.TargetName=&rectangle&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0&&Value=&4&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&EasingDoubleKeyFrame&KeyTime=&0:0:0.5&&Value=&16&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/DoubleAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemSelectedForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&SelectedPressed&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--选中按下鼠标左键并未弹起时Item的背景颜色--&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ObjectAnimationUsingKeyFrames&Storyboard.TargetProperty=&Foreground&&Storyboard.TargetName=&ContentPresenter&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DiscreteObjectKeyFrame&KeyTime=&0&&Value=&{StaticResource&ListBoxItemSelectedForegroundThemeBrush}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ObjectAnimationUsingKeyFrames&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Storyboard&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualState&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualStateGroup&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualStateGroup&x:Name=&FocusStates&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Focused&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&Unfocused&/&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&VisualState&x:Name=&PointerFocused&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/VisualStateGroup&
&&&&&&&&&&&&&&&&&&&&&&&&&/VisualStateManager.VisualStateGroups&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&Grid&x:Name=&InnerGrid&&Margin=&0,0,0,0&&Background=&Transparent&&Height=&75&&HorizontalAlignment=&Center&&VerticalAlignment=&Bottom&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Grid.RowDefinitions&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&RowDefinition&Height=&*&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&RowDefinition&Height=&Auto&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/Grid.RowDefinitions&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ContentPresenter&x:Name=&ContentPresenter&&ContentTemplate=&{TemplateBinding&ContentTemplate}&&ContentTransitions=&{TemplateBinding&ContentTransitions}&&Content=&{TemplateBinding&Content}&&HorizontalAlignment=&{TemplateBinding&HorizontalContentAlignment}&&Margin=&0&&VerticalAlignment=&{TemplateBinding&VerticalContentAlignment}&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&!--&Rectangle&x:Name=&FocusVisualWhite&&Opacity=&0&&StrokeDashOffset=&.5&&StrokeEndLineCap=&Square&&Stroke=&{StaticResource&FocusVisualWhiteStrokeThemeBrush}&&StrokeDashArray=&1,1&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rectangle&x:Name=&FocusVisualBlack&&Opacity=&0&&StrokeDashOffset=&1.5&&StrokeEndLineCap=&Square&&Stroke=&{StaticResource&FocusVisualBlackStrokeThemeBrush}&&StrokeDashArray=&1,1&/&--&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&TextBlock&Text=&{Binding&Name}&&FontSize=&24&&&HorizontalAlignment=&Center&&VerticalAlignment=&Bottom&&Foreground=&White&/&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rectangle&x:Name=&rectangle&&Fill=&{Binding&DicPic}&&Grid.Row=&1&&&Width=&160&&Height=&4&&Margin=&0,0,0,0&&HorizontalAlignment=&Center&&VerticalAlignment=&Bottom&/&
&&&&&&&&&&&&&&&&&&&&&&&&&/Grid&
&&&&&&&&&&&&&&&&&&&&&/Border&
&&&&&&&&&&&&&&&&&/ControlTemplate&
&&&&&&&&&&&&&/Setter.Value&
&&&&&&&&&/Setter&
&&&&&/Style&&&&
  以上就是在ListBox中更改ItemContainerStyle的样式,Item在选中和没选中时,实现自定义动画效果。
  该文章主要是介绍如何更改ItemContainerStyle的样式,根据自己项目的要求,从而实现不同的选中效果及动画。
  具体的效果图,如下所示,在选中一项时,该项中的Rectangle控件高度会比其他项高一点,每次切换Item时,都会使选中项在0.5秒内,把该项中的Rectangle控件的高度由4变成16。
  切换到另一项时,选项会跟着变化,如下图:
  由于是静态图片,无法展示出动画效果,如果有人需要,可以联系我,我把代码分享出来。
  本文来自License的博客,原文地址:/akwwl/archive//2769864.html
------分隔线----------------------------
从事移动应用开发,经常会用到 模拟器(Simulator)和仿真器(Emulator) ,本篇将总结对...
在Windows 8和Windows Phone应用开发中经常需要自定义一些Windows Store应用风格主题...
Windows 操作系统之所以风靡世界,是因为其易学易用,从用户的角度出发,让数以万计的...
日,微软发布Windows 8操作系统以及自主品牌平板电脑Surface,Windows作...
最近在做Silverlight,Windows Phone应用移植到Windows 8平台,在IIS8中测试一些传统W...
微软已经正式发布Windows 8操作系统,Windows 8采用全新的Modern界面并对触屏操作进行...C#中的checkedListBox点击右键选定一个list项
[问题点数:40分,结帖人zhangcy1993]
C#中的checkedListBox点击右键选定一个list项
[问题点数:40分,结帖人zhangcy1993]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。c#中如何清除listBox中的选定项?_百度知道
c#中如何清除listBox中的选定项?
SelectedIndexif(lb.Items!=-1)lb.RemoveAt(lb
其他类似问题
按默认排序
其他1条回答
listBox1.listBox1.Count-1.SelectedItem).RemoveAt(index).SelectedIndexCollection indices =
方法2void Btn_DeleteClick(=0.Count.Items, Si&gt.Count&0)
for(int n=selected -1方法1(从网上搜的)void Btn_DeleteClick(
if(indices.SelectedI=0.Ii--)
int selected=n&n--)
int index =indices[n].Items.Remove(
listBox1.EventArgs e)
for(int i=this.EventArgs e)
ListBox, System.listBox1.listBox1
listbox的相关知识
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁wpf listbox 右键单击--苦逼孩Silverlight请问WPF listbox请教WPF listbox我想实现的功能如下 将鼠标停留在listbox的某一ListBoxItem项 该项的右边出现 删除按钮 点击则可删除该项 请问各位大侠具体该怎样实现解决方案修改ListBoxItem的Template,每个Item都有删除按钮,不过出于隐藏状态,当获取到MouseOver事件时,置为可见.NET相关WPF ListBox图片的更替WPF ListBox图片的更换使用&ListBox.ItemTemplate&标签循环显示出几条新闻数据,里面放有Image和Label我想当鼠标悬浮的时候改变Image图片,用样式怎么实现,因为用的是ItemTemplate循环显示的,不能获得Image标签,所以只能用样式,但是我刚刚接触WPF,请C#WPF的ListBox排序有关问题WPF的ListBox排序问题ListBox.Items.SortDescriptions.ponentModel.SortDescription("Order",&nbspC#WPF 中listbox的用法疑义WPF 中listbox的用法疑问在listbox里绑定了Person对象来显示,我现在需要把某个对象从这个listbox里删除,想删除的通过person对象来传递,似乎不能直接用listbox.remove(person)来删除,那我应该怎么删除任何一个想.NET相关WPF ListBox图片的更换解决思路WPF ListBox图片的更换使用&ListBox.ItemTemplate&标签循环显示出几条新闻数据,里面放有Image和Label我想当鼠标悬浮的时候改变Image图片,用样式怎么实现,因为用的是ItemTemplate循环显示的,不能获得Image标签,所以只能用样式,但是我刚刚接触WPF,请VC/MFC各位软件工程师大哥,在ListBox中怎么响应右键单击消息各位程序员大哥,在ListBox中如何响应右键单击消息?各位老K,我最近做一个MFC程序,想在ListBox中响应右键消息,然后弹出菜单,可是发现类向导中没有RButton的消息,于是我从CListBox派生了新类(CMyListBox),但是我不知道派生了类以后接下来该怎么做~~~ 请大家指导下SilverlightWPF 触摸屏 拖动 滚动 ListBox,该如何解决WPF 触摸屏 拖动 滚动 ListBox就是类似于平板电脑上用手指滑动屏幕的切换效果,希望在ListBox中可以实现。点击ListBoxItem上时就能上下的滑动,不需要使用滚动条,请问这个怎么实现呢?解决方案手指按住屏幕后移动,内容根据手机移动方向相应显示对应内容。这东西你可以不考虑ListBox之类型可C#WPF怎么用滑轮控制LIstBox横向滚动条移动WPF如何用滑轮控制LIstBox横向滚动条移动我的程序是C#的,ListBox只有一行,但宽度不能显示所有列的,希望可以像竖向滚动条那样,滑动滑轮,就会上下移动请问如何实现滑轮控制LIstBox横向滚动条移动麻烦各位朋友帮帮忙!谢谢了!!解决方案winform真不知道哦有scrollview控件没?一般有横向滚动C#WPF在ListBox中显示图片响应慢,怎么处理WPF在ListBox中显示图片响应慢,怎么办?如题,当显示几张图片的时候速度还行,但是当显示100张图片(图片缩略图也不行)的时候反应超慢,而且PF使用率一直是1.7G左右,除非关闭程序才可以降下来。加载图片代码如下for (int i = 0; i & 100; i++){ Image.NET分析设计WPF的ListBox加载大量图片卡死的有关问题WPF的ListBox加载大量图片卡死的问题问题如下:ListBox的Itemplate是我自己定义的usercontrol,每个usercontrol都有一个image,当加载listbox的时候(大概有200个左右usercontrol)会很慢,而且加载完成之后移动鼠标或者滚轮都会造成卡死!!ListBox代码C#WPF给ListBox平添效果:鼠标滑过每项时背景色改变WPF给ListBox添加效果:鼠标滑过每项时背景色改变类似VS2010中Toolbox的效果,鼠标滑过每一项的时候背景色都改变,给个思路或代码,刚学这个,什么都不会。&ListBoxHeight="276"HorizontalAlignment="Left"NameSilverlightWPF中ListBox的模板中控件的事情?该如何处理WPF中ListBox的模板中控件的事情?C# code&ListBox Margin=&0& Name=&lbErrorList& ItemContainerStyle=&{StaticResource ListBoxItemStyle}&quotC#WPF中的ListBox中如何显示是当前记录是第几条记录WPF中的ListBox中怎么显示是当前记录是第几条记录WPF中的ListBox中怎么显示是当前记录是第几条记录,比如第一条记录显示为沙发,第二条显示板凳。。。跟论坛差不多的那种解决方案ListBox.SelectedIndex例子httpC#WPF实现鼠标滑轮滚动,ListBox内容横向滚动,该如何解决WPF实现鼠标滑轮滚动,ListBox内容横向滚动现在ListBox绑定的内容只有一行,列有七列,宽度少于七列的宽度请问怎样实现鼠标滑轮滚动时,ListBox的内容横向移动??麻烦大家帮帮忙,谢了!!解决方案探讨现在ListBox绑定的内容只有一行,列有七列,宽度少于七列的宽度请问怎样实现鼠标滑轮滚动时C#WPF中想让LISTBOX有鼠标滑过效果,该如何解决WPF中想让LISTBOX有鼠标滑过效果就是在鼠标滑过的时候该项有颜色变化网上找到个C#的C# codeprivate void listBox1_MouseMove(object sender, MouseEventArgs e){ int AIndex -->热门推荐最新更新返回顶部页面导航:
→ 正文内容 C# ListBox控件
C#入门教程之ListBox控件使用方法
本文讲一下C#中ListBox控件的使用方法,也可以作为一门入门教程吧,请下本文的详细讲解。
ListBox控件的使用: 1)控件属性 Items SelectedItems SelectioModes 2)数据绑定 DataSoure DisplayMember ValueMenber 3)实例 下面开始一一说明上面的ListBox控件的使用。 首先来说控件的属性, (1)Items:使用此属性获取列表控件项的属性。此属性可用于确定列表控件中的选定项。添加items时既可以设计时静态添加,也可以在代码中动态添加。如果不想显示设计时添加的items,可以在代码中添加this.listBox1.Items.Clear();只显示在代码中添加的选项。 (2)SelectedItems:获取包含ListBox中当前选定项的集合。 (3)SelectioModes:获取或设置在ListBox中选择项所用的方法。一共有四个值可选;默认为 SelectionMode.One,只能选中一个;属性值为none时不能选择;当属性MultiExtended 时,按下 Shift 键的同时单击鼠标或者同时Shift 键和箭头键之一(向上键、向下键、向左键和向右键),会将选定内容从前一选定项扩展到当前项。按 Ctrl 键的同时单击鼠标将选择或撤消选择列表中的某项;当该属性设置为MultiSimple 时,鼠标单击或按空格键将选择或撤消选择列表中的某项。 接下来说一哈数据绑定,通常数据都是可变的,所以说就需要数据绑定。数据绑定有几种,一种就是绑定从数据库中获取的DataTable或者是DataSet;另外一种就是自定义一个类,绑定自定义类中的数据。c#中的数据绑定与ASP.NET中的数据绑定还有一点区别,ASP.NET中绑定数据后还要调用一个DataBind方法,而在c#中就不需要。而DisplayMember获取或设置要显示的属性。 最后我们来做一个实例如图所示:下面我们只是说一哈几个重要的方法的实现,具体代码就不在这写了。将左边框中的选项放到右边框中去。代码:
代码如下: for (int i = this.listBox1.SelectedItems.Count - 1; i &= 0;i -- ) { Menu menu = (menu)this.listBox1.SelectedItems[i]; this.listBox2.Items.Add(menu); this.listBox1.Items.Remove(i); }
上面虽然实现了功能但是有一个问题,就是左边的项到了右边后变成了倒序。这是我们需要将添加和移出分开写,代码:
代码如下: for (int i = 0; i & this.listBox1.SelectedItems.Ci++ ) { Menu menu = (menu)this.listBox1.SelectedItems[i]; this.listBox2.Items.Add(menu); } for (int i = this.listBox1.SelectedItems.Count - 1; i &= 0; i--) { this.listBox1.Items.Remove(i); }
到现在为止还一个问题就是当选择框中的前面几个项的时候右移没有问题,但选择后面几个项时移到右边框中的是后面几个项,而左边框中移出的是前面几个项,造成这个问题的原因是我们将 SelectedItems和Items混为一谈了。这是很多初学者容易犯的错误。代码:
代码如下: for (int i = 0; i & this.listBox1.SelectedItems.Ci++ ) { Menu menu = (menu)this.listBox1.SelectedItems[i]; this.listBox2.Items.Add(menu); } for (int i = this.listBox1.SelectedItems.Count - 1; i &= 0; i--) { Menu menu = (menu)this.listBox1.SelectedItems[i]; this.listBox1.Items.Remove(menu); }
这样的话就对了。 个人自学不知说的对不对,希望各位支持支持,欢迎指正。
您可能感兴趣的文章:
上一篇:下一篇:
最 近 更 新
热 点 排 行
12345678910

我要回帖

更多关于 c listbox删除选中项 的文章

 

随机推荐