WPF 自定义范围分组
<Window x:Class="ViewExam.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="437.165" Width="553.161" Loaded="Window_Loaded_1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ListBox Name="lstProducts" DisplayMemberPath="ModelName" Height="200" SelectionChanged="lstProducts_SelectionChanged_1">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="White" Background="LightGreen" Margin="5,0,0,0" Padding="3"></TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
<Grid Grid.Row="1" DataContext="{Binding ElementName=lstProducts, Path=SelectedItem}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock>Model Number</TextBlock>
<TextBox Text="{Binding Path=ModelNumber}" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="1">Model Name</TextBlock>
<TextBox Text="{Binding Path=ModelName}" Grid.Column="1" Grid.Row="1"></TextBox>
<TextBlock Grid.Row="2">Unit Cost</TextBlock>
<TextBox Text="{Binding Path=UnitCost}" Grid.Column="1" Grid.Row="2"></TextBox>
<TextBlock Grid.Row="3">Description</TextBlock>
<TextBox Text="{Binding Path=Description}" TextWrapping="Wrap" Grid.Row="5" Grid.ColumnSpan="2"></TextBox>
</Grid>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Button Name="btnPrevious" Click="btnPrevious_Click_1">previous</Button>
<Label x:Name="lblPosition" Width="400"></Label>
<Button Name="btnNext" Click="btnNext_Click_1">Next</Button>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Label>Price than</Label>
<TextBox Name="txtMin" Width="200"></TextBox>
<Button Name="btnFilter" Click="btnFilter_Click_1">Filter</Button>
<Button Name="btnRemoveFilter" Margin="3,0,0,0" Click="btnRemoveFilter_Click_1">Remove Filter</Button>
</StackPanel>
</Grid>
</Window>
using DBAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ViewExam
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private ListCollectionView view;
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
ICollection<Product> products = StoreDB.GetProducts();
lstProducts.ItemsSource = products;
this.DataContext = products;
view = (ListCollectionView)CollectionViewSource.GetDefaultView(products);
//view.Filter = new Predicate<object>(FilterProduct);
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("CategoryID", System.ComponentModel.ListSortDirection.Ascending));
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("UnitCost", System.ComponentModel.ListSortDirection.Ascending));
//view.GroupDescriptions.Add(new PropertyGroupDescription("CategoryID"));
PriceRangeProductGrouper grouper = new PriceRangeProductGrouper();
grouper.GroupInterval = 50;
view.GroupDescriptions.Add(new PropertyGroupDescription("UnitCost",grouper));
view.CurrentChanged += view_CurrentChanged;
view_CurrentChanged(this, null);
}
private bool FilterProduct(object obj)
{
Product pro = (Product)obj;
return pro.UnitCost > 100;
}
void view_CurrentChanged(object sender, EventArgs e)
{
lblPosition.Content = "Record " + (view.CurrentPosition + 1).ToString() + " of " + view.Count.ToString();
btnPrevious.IsEnabled = view.CurrentPosition > 0;
btnNext.IsEnabled = view.CurrentPosition < view.Count - 1;
}
private void btnPrevious_Click_1(object sender, RoutedEventArgs e)
{
view.MoveCurrentToPrevious();
}
private void btnNext_Click_1(object sender, RoutedEventArgs e)
{
view.MoveCurrentToNext();
}
ProductByPriceFilter filter;
private void btnFilter_Click_1(object sender, RoutedEventArgs e)
{
decimal min = Convert.ToDecimal(txtMin.Text);
filter = new ProductByPriceFilter(min);
view.Filter = filter.FilterItem;
}
private void btnRemoveFilter_Click_1(object sender, RoutedEventArgs e)
{
view.Filter = null;
}
private void lstProducts_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
view.MoveCurrentTo(lstProducts.SelectedItem);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ViewExam
{
public class PriceRangeProductGrouper:IValueConverter
{
public int GroupInterval { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
decimal price = (decimal)value;
if (price < GroupInterval)
{
return string.Format(culture, "Less than {0:C}", GroupInterval);
}
else
{
int interval = (int)price / GroupInterval;
int lowerLimit = interval * GroupInterval;
int upperLimit = (interval + 1) * GroupInterval;
return string.Format(culture, "{0:C} to {1:C}", lowerLimit, upperLimit);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using DBAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewExam
{
public class ProductByPriceFilter
{
public decimal MinimumPrice { get; set; }
public ProductByPriceFilter(decimal minimumPrice)
{
MinimumPrice = minimumPrice;
}
public bool FilterItem(object item)
{
Product pro = (Product)item;
if (pro!=null)
{
return pro.UnitCost > MinimumPrice;
}
return false;
}
}
}
WPF 自定义范围分组的更多相关文章
- WPF 自定义柱状图 BarChart
WPF 自定义柱状图 当前的Telerik控件.DevExpress控件在图表控件方面做得不错,但是有时项目中需要特定的样式,不是只通过修改图表的模板和样式就能实现的. 或者说,通过修改当前的第三方控 ...
- wpf 自定义圆形按钮
wpf 自定义圆形按钮 效果图 默认样式 获取焦点样式 点击样式 下面是实现代码: 一个是自定义控件类,一个是控件类皮肤 using System; using System.Collections. ...
- WPF自定义窗口基类
WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义.继承自定义窗口的类xaml文件的根节点就不再是<Window>,而是自定义窗口类名(若自定义窗口与继承者不在同一个命名 ...
- WPF 自定义 MessageBox (相对完善版)
WPF 自定义 MessageBox (相对完善版) 基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...
- WPF自定义Window样式(2)
1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...
- WPF自定义Window样式(1)
1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...
- WPF自学入门(九)WPF自定义窗口基类
今天简单记录一个知识点:WPF自定义窗口基类,常用winform的人知道,winform的窗体继承是很好用的,写一个基础窗体,直接在后台代码改写继承窗体名.但如果是WPF要继承窗体,我个人感觉没有理解 ...
- WPF自定义TabControl样式
WPF自定义TabControl,TabControl美化 XAML代码: <TabControl x:Class="SunCreate.Common.Controls.TabCont ...
- WPF 自定义ComboBox样式,自定义多选控件
原文:WPF 自定义ComboBox样式,自定义多选控件 一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样 ...
随机推荐
- android开发音乐播放器--Genres和Art album的获取
最近在做一个项目,其中涉及到音乐播放器.当用到Genres和Art album时花费了一些时间才搞定,今天把方法草草列出,以供自己以后忘记时查看,也希望可以帮助碰到同样问题的道友!! 一.Genres ...
- 程序猿的还有一出路:大数据project师
非常多年前我非常郁闷地写了一篇博客<程序猿的出路在哪里?>,之所以郁闷.我记得是看了中国男足的比赛,不由自主对照自已苦逼的程序猿生涯,以前对中国软件的感情有如对中国男足,绝望到没有不论什么 ...
- 【59.49%】【codeforces 554B】Ohana Cleans Up
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- JavaScript调用ATL COM(二)
作者:朱金灿 来源:http://blog.csdn.net/clever101 在上篇文章中介绍了如何在JS中调用ATL COM: JS调用ATL COM中的C++接口的做法 现在我们可以把它嵌入到 ...
- 学习鸟哥的Linux私房菜笔记(16)——Ubuntu中建立ftp服务
1.安装vsftpd,如下图所示:sudo apt-get install vsftpd 2.查看本机是否可以连接ftp 如上图所示,发现login failed了,怎么办呢?我们来看看vsftpd的 ...
- NOIP模拟 乘积 - 状压dp + 分组背包
题目大意: 给出n和k,求从小于等于n的数中取出不超过k个,其乘积是无平方因子数的方案数.无平方因子数:不能被质数的平方整除. 题目分析: 10(枚举\(n\le8\)),40(简单状压\(n\le1 ...
- yii2.0表单《《提交》》变量设置
public $enableCsrfValidation = false;
- Android开发之 shape的使用
android shape的使用 shape用于设定形状,能够在selector,layout等里面使用,有6个子标签,各属性例如以下: <?xml version="1.0" ...
- QWidget 之paint部分杂记(从Qt4.0到4.8的进化,在Qt 4.4中,Alien Widget诞生了)
Qt 4.0 automatically double-buffers Qt 4.1 QWidget::autoFillBackground Qt 4.2 delayed widget creatio ...
- expdp&impdp
1 创建逻辑文件夹,该命令不会在操作系统创建真正的文件夹,最好以system等管理员创建. create directory dpdata1 as '/opt/oracle/dpdata1'; c ...