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. FI配置步骤清单

    1.定义公司代码   配置路径: R/3定制IMG的实施指南>企业结构>定义>财务会计>定义, 复制, 删除, 检查公司代码 事务代码 EC01 2.编辑科目表清单   配置路 ...

  2. Sqoop安装与应用过程

    1.  参考说明 参考文档: http://sqoop.apache.org/ http://sqoop.apache.org/docs/1.99.7/admin/Installation.html ...

  3. flutter 监控返回键

    return new WillPopScope( child: Scaffold( body: new Center( child: new Column( children: <Widget& ...

  4. javascript获取网页各种高宽及位置总结

    screen对象 获取屏幕的高宽(分辨率) screen.width //屏幕的宽 screen.height //屏幕的高 screen.availWidth //屏幕可用宽度 屏幕的像素高度减去系 ...

  5. APP主要测试类型及测试点总结

    根据测试重点区分 一.功能性测试 根据产品需求文档编写测试用例: 根据设计文档编写测试用例: 根据UI原型图编写测试用例 二.UI测试 原型图/效果图对比 用户体验 数据模拟:需要考虑正式环境可能的数 ...

  6. innodb 表锁和行锁

    表锁  表锁相关结构: table->locks:数据字典table保存这个表上的所有表锁信息 trx->lock.table_locks:每个事务trx保存该事务所加的所有表锁信息 tr ...

  7. [SQLSERVER] 把TransactionLog截断

    注意:以下语句非常危险 --BACKUP LOG MyDb TO DISK=’NUL:’

  8. Freemarket语法

    <#--freemarker HashMap取值--> <#assign maps={"1":"张三丰","2":&quo ...

  9. ensp 路由器无法启动

    出现错误代码 40.41等几乎都是虚拟机问题, 卸载干净后重新安装就好.推荐卸载软件:iobit uninstaller 安装注册后无法创建Host-Only,最好更换虚拟机版本, 我用的虚拟机版本是 ...

  10. 【转】Java学习---10个测试框架介绍

    [原文]https://www.toutiao.com/i6594302925458113027/ JAVA 程序员需要用到 10 个测试框架和库 Java 程序员需要用到十大单元测试和自动化集成测试 ...