UI:

<Window x:Class="WoZhuLianyuanTool.SendContentsWind"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Name="MWind"
Height="366" Width="617"
Title="MainWindow" ShowInTaskbar="False"
WindowStyle="None" Background="{x:Null}" AllowsTransparency="True"
MouseLeftButtonDown="Window_MouseLeftButtonDown" xmlns:my="clr-namespace:WoZhuLianyuanTool" WindowStartupLocation="CenterScreen" RenderTransformOrigin="0.5,0.5">
<Window.Resources> <my:StringToBoolConverter x:Key="StringToBoolConverter1" />
</Window.Resources>
<Window.RenderTransform>
<ScaleTransform x:Name="t" ScaleX="1" ScaleY="1"> </ScaleTransform>
</Window.RenderTransform>
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0.5" To="1" Storyboard.TargetName="t" Storyboard.TargetProperty="ScaleX" Duration="0:0:2"> <DoubleAnimation.EasingFunction>
<ElasticEase Oscillations="3"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation From="0.5" To="1" Storyboard.TargetName="t" Storyboard.TargetProperty="ScaleY" Duration="0:0:2"> <DoubleAnimation.EasingFunction>
<ElasticEase Oscillations="3"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation> </Storyboard> </BeginStoryboard>
</EventTrigger>
</Window.Triggers> <Grid RenderTransformOrigin="0.5,0.5"> <Grid.ColumnDefinitions>
<ColumnDefinition Width="561*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions> <Border CornerRadius="10,10,10,10" Margin="10,10,2,10" Height="Auto" BorderBrush="White" BorderThickness="6" Background="#FFEBEBEB">
<Border.Effect>
<DropShadowEffect Opacity="1" ShadowDepth="4">
</DropShadowEffect>
</Border.Effect>
<Grid Name="gridParent"> <Grid Name="gridTitle" Margin="0,0,0,259">
<Rectangle Fill="#FFFF7AA4" Height="42" VerticalAlignment="Top" Margin="0,0,0,0" /> <Label Name="lbVersion" Foreground="WhiteSmoke" Width="362" Height="24" Content="--------" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,5,0,0" Background="#02E2D3D3"/> </Grid> <Grid Margin="0,42,0,0">
<ListView Name="listView" ItemsSource="{Binding}" Height="179" Margin="0,42,0,32"> <ListView.View>
<GridView>
<GridViewColumn Width="26" Header="勾选" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding id}" Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" IsChecked="{Binding Path=isChecked2,Mode=OneTime}"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Width="458" Header="msg" DisplayMemberBinding="{Binding msg}"/>
<GridViewColumn Width="66" Header="del" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Tag="{Binding id}" Content="删除" Click="btnDel_Click"></Button>
</DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn> </GridView>
</ListView.View>
</ListView> <TextBox Height="23" Margin="8,10,107,0" Name="txtMsg" VerticalAlignment="Top" />
<Button VerticalAlignment="Top" HorizontalAlignment="Right" Height="30" Width="86" Margin="0,6,5,0" Content="add" Name="btnAdd" Click="btnAdd_Click"></Button>
<Label VerticalAlignment="Bottom" Name ="lbStatus" Content="000"></Label> </Grid> </Grid>
</Border> <!--左上角的“X”叉形按钮-->
<Button x:Name="x" Content="Button" HorizontalAlignment="Right" Height="24" Style="{DynamicResource XButtonStyle}" VerticalAlignment="Top" Width="46" Margin="0,18,9,0" Click="btnClose_Click" /> </Grid>
</Window>

  

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using System.Globalization; namespace WoZhuLianyuanTool
{
/// <summary>
/// Interaction logic for SendContentsWind.xaml
/// </summary>
public partial class SendContentsWind : Window
{
public SendContentsWind()
{
InitializeComponent();
dbtool = new DBTools();
listData = dbtool.LoadSendContentItems();
listView.DataContext = listData;
listView.ItemsSource = listData;
lbStatus.Content = "共" + listData.Count + "项,已选" + listData.Count(n => n.isChecked2 == true);
Loaded += new RoutedEventHandler(SendContentsWind_Loaded); }
List<SendContentItem> listData = null;
DBTools dbtool = null;
void SendContentsWind_Loaded(object sender, RoutedEventArgs e)
{ } private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
} private void btnClose_Click(object sender, RoutedEventArgs e)
{
Close();
} private void btnAdd_Click(object sender, RoutedEventArgs e)
{ if (txtMsg.Text.Trim() == "") return;
dbtool.AddSendContentItem(new SendContentItem (){ id=Guid.NewGuid().ToString(), isChecked="True", msg=txtMsg.Text });
txtMsg.Text = "";
updateList();
listView.ScrollIntoView(listView.Items[listView.Items.Count -1]); }
private void btnDel_Click(object sender, RoutedEventArgs e)
{
dbtool.DelSendContentItem("" + (sender as Button ).Tag);
updateList();
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
// MessageBox.Show(""+(sender as CheckBox).IsChecked);
dbtool.UpdateSendContentItem("" + (sender as CheckBox).Tag,(bool )(sender as CheckBox).IsChecked);
updateList2(); } private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
CheckBox ck=(sender as CheckBox);
//MessageBox.Show("" + (sender as CheckBox).IsChecked);
dbtool.UpdateSendContentItem(""+ck.Tag,(bool)ck.IsChecked);
updateList2();
} private void updateList() { listData = dbtool.LoadSendContentItems();
listView.ItemsSource = listData;
lbStatus.Content = "共" + listData.Count + "项,已选" + listData.Count(n=>n.isChecked2==true );
} private void updateList2()//not rebind
{
listData = dbtool.LoadSendContentItems();
lbStatus.Content = "共" + listData.Count + "项,已选" + listData.Count(n=>n.isChecked2 ==true);
} }  public class StringToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value==null)
            {
                return true;
            }
           // int val = System.Convert.ToInt32(value);
bool b=true ;
if (value.ToString() == "0" || value.ToString().ToLower() == "false") { b = false;
} if (value.ToString() == "1" || value.ToString().ToLower() == "true")
{ b = false;
} return b;
        }         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value==null)
            {
                return "0";
            }             return ((bool)value) ? "true" : "false";
        }
    } }

  

DBTool class:

        //---------------------------------------------------------------------------

        public bool CreateTable_SendContent()
{ bool isOK = false;
string strCmd = "";
SQLiteConnection conn = new SQLiteConnection(strConn);
try
{ if (conn.State != ConnectionState.Open)
{
conn.Open();
} SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
SQLiteTransaction myTrans; strCmd = @"select count(1) cnt from sqlite_master where type='table' and name = 'SendContent' ";
cmd.CommandText = strCmd;
int cnt = int.Parse("" + cmd.ExecuteScalar());
if (cnt <= 0)
{//add table
// Start a local transaction
myTrans = conn.BeginTransaction(System.Data.IsolationLevel.Serializable);
cmd.Transaction = myTrans;
strCmd = @"ALTER TABLE members ADD flag_no_ReSend integer DEFAULT 0";
strCmd = @"create table SendContent(id text,msg text,isChecked text,primary key (id))";
cmd.CommandText = strCmd;
cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
FillTableSendContent();// fill test content
}
isOK = true; } catch (Exception ex)
{ if (conn.State != ConnectionState.Closed)
{
conn.Close(); }
isOK = false;
MessageBox.Show("SendContent:" + ex.Message); } return isOK; } /// <summary>
/// fill test contents
/// </summary>
/// <returns></returns>
public bool FillTableSendContent()
{ bool isOK = false;
string strCmd = "";
SQLiteConnection conn = new SQLiteConnection(strConn);
try
{ if (conn.State != ConnectionState.Open)
{
conn.Open();
} SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
SQLiteTransaction myTrans;
// Start a local transaction
myTrans = conn.BeginTransaction(System.Data.IsolationLevel.Serializable);
cmd.Transaction = myTrans;
strCmd = @"insert into SendContent(id,msg,isChecked) select '"+ Guid.NewGuid().ToString()+"','test msg','1'";
cmd.CommandText = strCmd;
cmd.CommandText = strCmd;
cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
isOK = true;
} catch (Exception ex)
{ if (conn.State != ConnectionState.Closed)
{
conn.Close(); }
isOK = false;
MessageBox.Show("SendContent:" + ex.Message); } return isOK; } public List<SendContentItem> LoadSendContentItems() { List<SendContentItem> list = new List<SendContentItem>();
DataTable tb = getTable("select * from SendContent");
if(tb!=null && tb.Rows.Count>0){
foreach (DataRow r in tb.Rows) {
list.Add(new SendContentItem() { id = "" + r["id"], msg = "" + r["msg"], isChecked = "" + r["isChecked"] }); } } return list; } public bool UpdateSendContentItem(string id, bool isChecked, string newMsg="")
{ int i = 0;
if (newMsg == "")
{
i = ExeSql("update SendContent set isChecked='" + isChecked + "' where id='" + id + "'");
}
else {
i = ExeSql("update SendContent set msg='"+ newMsg +"', isChecked='" + isChecked + "' where id='" + id + "'");
}
return i> 0; } public bool AddSendContentItem(SendContentItem item){
int i = 0;
i = ExeSql( @"insert into SendContent(id,msg,isChecked) select '"+ Guid.NewGuid().ToString()+"','"+item.msg +"','"+ item.isChecked+"'");
return i > 0; }
public bool DelSendContentItem(string id )
{
int i = 0;
i = ExeSql( @"delete from SendContent where id='"+ id +"'");
return i > 0; } //--------------------------------------------------------------------------- public class SendContentItem { public string id { get; set; }
public string msg { get; set; }
public string isChecked { get; set; }
public bool isChecked2 { get{
return isChecked=="1" || isChecked.ToLower()=="true";
}
set{ } } }

  

WPF listview Test Message list的更多相关文章

  1. WPF ListView 选中问题

    WPF ListView 选中问题  摘自:http://www.cnblogs.com/BBHor/archive/2013/04/28/VisualTreeHelper-PreviewMouseD ...

  2. [WPF]ListView点击列头排序功能实现

    [转]   [WPF]ListView点击列头排序功能实现 这是一个非常常见的功能,要求也很简单,在Column Header上显示一个小三角表示表示现在是在哪个Header上的正序还是倒序就可以了. ...

  3. WPF ListView 居中显示

    原文:WPF ListView 居中显示 今天遇到的问题: 方法1:设置GridViewColumn的ActualWidth <ListView > <ListView.View&g ...

  4. WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画

    原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同 ...

  5. WPF listview item mouse enter/over popup

    This is because the routing strategy of the Loaded event is Direct, which means that the routed even ...

  6. wpf ListView DataTemplate方式的鼠标悬停和选中更改背景色

    今天使用wpf技术弄一个ListView的时候,由于需求需要,需要ListView显示不同的数据模板,很自然的使用了DataTemplate方式来定义多个数据模板,并在ListView中使用ItemT ...

  7. WPF ListView点击删除某一行并获取绑定数据

    最近在开发WPF程序时遇到一个问题,在gridview中希望实现在每一行最后添加一个删除的按钮,但是发现点击每行的button时只会触发button的点击事件,并没有选中这一行,此时调用list.Se ...

  8. wpf listview

    <Window x:Class="WpfTutorialSamples.ListView_control.ListViewGridViewSample"        xml ...

  9. wpf listview 换行

    <ListView  Name="listView1" VerticalAlignment="Top" Height="600" Ma ...

随机推荐

  1. Wireshark wireshake数据包分割及捕包过滤器介绍

    wireshake数据包分割及捕包过滤器介绍 by:授客 QQ:1033553122 wireshake自带工具editcap分割数据包 操作: 进入到目录,然后 editcap.exe -c < ...

  2. windows 服务器MYSQL 数据库安装配置

    一.到官网下载MYSQL 打开官网地址:www.mysql.com, 选择 DOWNLOADS,进入到MySQL的下载页面,在页面的底部有一个MySQL Community Edition, 并且下面 ...

  3. Problem2-Project Euler

    Even Fibonacci numbers   Each new term in the Fibonacci sequence is generated by adding the previous ...

  4. Oracle EBS GL总账凭证取值

    SELECT gh.je_header_id, gh.period_name, gh.default_effective_date, gh.je_source, gs.user_je_source_n ...

  5. SQL 时间戳转换为日期

    , '1970-01-01 00:00:00') 其中Timestamp为10位的时间戳,+8*3600是获取中国北京时间(东八区)

  6. RHEL7.3安装python3.6.1

    RHEL7.3 install python3.6.1 steps 1. download Python-3.6.1.tgz2. tar -zxvf Python-3.6.1.tgz3. yum in ...

  7. Redis缓存穿透、缓存雪崩、redis并发问题分析

    把redis作为缓存使用已经是司空见惯,但是使用redis后也可能会碰到一系列的问题,尤其是数据量很大的时候,经典的几个问题如下: (一)缓存和数据库间数据一致性问题分布式环境下(单机就不用说了)非常 ...

  8. MySQL运维之--xtrabackup工具的原理和使用方法

    Xtrabackup工具的介绍 xtrabackup是percona公司开发的一款自由.免费.开源的一款备份工具,他的备份特点就是:支持热备.备份速度快. xtrabackup包含两个重要的工具:in ...

  9. 2.1Python基础语法(一)之注释与数据类型:

    返回总目录 目录: 1.注释 2.乱码 3.变量 4.数据类型 5.数据的转换 6.动态,静态和强类型,弱类型 (一)注释:(编译时是被编译器忽略的) 1.注释的分类: 2.特殊注释: (二)乱码:( ...

  10. 用JS制作《飞机大作战》游戏_第1讲(素材查找和界面框架搭建)-陈远波

    一.查找素材: 二.分析游戏界面框架: 登录界面.游戏界面.暂停游戏界面.玩家死亡后弹出界面:并对应的界面包含什么元素: 三.分别搭建以上四个界面: 1.登录界面与游戏界面框架(隐藏游戏界面,四个界面 ...