WPF ListBox】的更多相关文章

首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的,SystemColors的HighlightBrushKey和HighlightTextBrushKey分别代表ListBoxItem被选中时文字和背景颜色,没有Highlight的BrushKey代表ListBox没有焦点时的选中项文字和背景颜色: <ListBox> <ListBox.Resources> <Style TargetType="List…
本文来源 http://wshoufeng1989.blog.163.com/blog/static/202047033201282911633670/  风随影动的博客 使用数据库AllData ,我们的程序会从S_Province表中读取数据,并绑定! 表结构如图所示: 程序将读取城市名称,创建时间,修改时间,列在一个WPF ListBox控件.最后的ListBox如图所示: 现在来看我们的XAML文件.创建数据模板listBoxTemplate.数据模板有三块,第一块显示的是城市名称:第二…
原文:WPF : ListBox的几种Template属性 属性名 属性的类名 功能 示例 Template ControlTemplate 定义控件自身的外观.其子元素的布局可以自定义,也可以由ItemsPresenter定义. <Style TargetType="ListBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetTy…
(下图:进行多项选择的ListBox) 首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的,SystemColors的HighlightBrushKey和HighlightTextBrushKey分别代表ListBoxItem被选中时文字和背景颜色,没有Highlight的BrushKey代表ListBox没有焦点时的选中项文字和背景颜色: 1 <ListBox> 2 3 <ListBox.Resources> 4 5 &…
原文:wpf listbox 选中项 上移下移 private void MoveUp_Click(object sender, RoutedEventArgs e)         {             DataRowView rowView = this.listScrip.SelectedItem as DataRowView;             if (rowView == null)             {                 return;       …
WPF ListBox 横向排列   如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如: <ListBox><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel Orientation=”Horizontal” IsItemsHost=”True”/></ItemsPanelTemplate></ListBox.ItemsP…
1.使用ListBox绑定Dictionary字典数据 ListBox常用事件SelectionChanged private void bindListBox() { Dictionary<string, string> dic = new Dictionary<string, string>(); foreach (var item in Fonts.SystemFontFamilies.OrderBy(q => q.Source)) { dic.Add(item.Sou…
ListBox的滚动方式 分为像素滚动和列表项滚动 通过ListBox的附加属性ScrollViewer.CanContentScroll来设置.因此ListBox的默认模板中,含有ScrollViewer,ScrollViewer下存放列表内容 <ScrollViewer FocusVisualStyle="{x:Null}"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.…
今天更改ListBox,用到ItemContainerStyle设置样式,设置Style.Triggers时,BackGround和BorderBrush均无效,其他效果正常. 翻看WPF编程宝典,发现代码没问题,下载源码之后,发现效果一样不行.在群里求助之后,得到解决.win8问题,编程宝典的作者用的是win7,xp也正常,唯独win8没有效果. 原问题链接:http://stackoverflow.com/questions/491293/why-cant-i-set-the-backgro…
记录一些ListBox的用法 设置ListBox选中项的背景颜色 如何为标准的ListBox添加ItemClick事件 连续选择同一项时SelectionChanged 事件不响应的问题 1.设置ListBox选中项的背景颜色 采用模板 先看一下效果图: 在设置listbox选中样式是遇到一个问题:选中项的背景设置不起作用 经过一段时间的挣扎后找到原因,模板里的控件要设置 Background="{TemplateBinding Background}" TextBlock.Foreg…
有时候控件并非维护本身逻辑,而是依赖于父子元素的,如了上诉的ContentPresenter,我们还有一个非常常用的ListBox控件,因为继承自ItemsControl,所以有一个ItemsPanel属性作为集合元素承载容器,但集合控件本身却不负责呈现控件,那么这个任务就留给了子元素ItemsPresenter,其实用也很简单,只要把ItemsPresenter放在内部模板中,那么ItemsPresenter则会去检测父元素是否为集合控件,然后将ItemsPanel添加到其内部视觉树当中 <S…
public partial class Example : UserControl { private ScrollViewer myScrollViewer; public Example() { InitializeComponent(); } private void ScrollViewer_Loaded(object sender, System.Windows.RoutedEventArgs e) { myScrollViewer = (sender as ScrollViewer…
public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject { if (obj != null) { ; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null &&…
ListBox  默认是UI虚拟化的. 1. 原生使用  <ListBox VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling"> </ListBox>  为ListBox 设置一个ItemTemplate <DataTemplate x:Key="ListBoxDataTemplate">…
<ListBox Name="lbLogInfo"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> &…
在网上很难找最简单的案例,都是一大片,看着都头疼: 试试举一反三,如果把结果赋给DataContext这个属性,那就前台需要绑定ItemsSource="{Binding}",请注意.直接赋给ItemsSourc就不要绑定了: 后台代码: List<string> list = new List<string>(); ; i < ; i++) { list.Add("sas" + i); } this.mb.DataContext =…
向ListBox绑定数据源时,如果数据量过大,可能会使得程序卡死,这是就需要一条一条的向ListBox的数据源中添加记录了,下面是个小Demo: 1.前台代码,就是一个ListBox控件 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schema…
<ListBox ItemTemplate="{StaticResource CardPictureTemplate}" VirtualizingPanel.CacheLength="20,20" MinWidth="160" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.CacheLengthUnit="Item" x:Name=…
页面代码: <Grid Grid.Row="0" Grid.Column="2"> <ListBox x:Name="lvStep" Style="{StaticResource StepTemp}" Width="830" HorizontalAlignment="Left" ItemsSource="{Binding DataSteps,Mode=OneW…
一.每行显示固定列数 <ListBox ItemsSource="{Binding DataList}" Style="{DynamicResource ListBoxStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >                    <ListBox.ItemsPanel>                        &l…
1. 首先继承一个listbox,来获得按住ctrl键时,点击的item public class ListBoxEx : ListBox { public BeatTemplateWave GetAnitem() { var obj = this.AnchorItem; if (obj != null) { Type type = obj.GetType(); System.Reflection.PropertyInfo propertyInfo = type.GetProperty("Ite…
项目中经常使用需要根据搜索条件查询数据,然后用卡片来展示数据.用卡片展示数据时,界面的宽度发生变化,希望显示的卡片数量也跟随变化.WrapPanel虽然也可以实现这个功能,但是将多余的部分都留在行尾,十分不美观,最好是能够将多余的宽度平分在每个ListBoxItem之间,比较美观,也符合项目需求.如下便是我自己实现的Panel: using System; using System.Collections.Generic; using System.Linq; using System.Text…
公司项目有个需求,UI界面支持动态平均分割界面,想了想便想到用ListBox来实现,用UniformGrid作为ListBox的ItemsPanelTemplate,通过动态改变UniformGrid的Columns属性,可以动态分割界面.具体实现如下所示: <Window x:Class="WpfDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"…
listBox外部包裹一层 <ScrollViewer VerticalScrollBarVisibility="Auto"> 然后修改listBox的style,取消样式内部的ScrollViewer…
<ListBox Name="listBox" SelectionMode="Extended"> <ListBox.Resources> <Style TargetType="{x:Type ListBoxItem}"> <EventSetter Event="ListBoxItem.PreviewMouseLeftButtonDown" Handler="lbItem_P…
搞了个ListBox删除选择项,开始老是不能把选择项删除干净,剩下几个.后来调试一下原来是ListBox在删除一个选择项之后立即更新,选择项也有变化.结果我想了个这样的方法来删除呵呵. Department_Users是ListBox int SelectItems = Department_Users.SelectedItems.Count;            if (Department_Users.SelectedItems.Count > 0)            {       …
解决方案: 将Listbox 的ItemTemplateSelector 改为 ItemContainerStyle中ContentPresenter ContentTemplateSelector 属性…
<Window x:Class="XamlTest.Window3"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="Window3" Height="300&qu…
<ListBox ScrollViewer.VerticalScrollBarVisibility = "Disabled"; </ListBox>…
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Share…