当前位置: 首页 > news >正文

深圳网站建设微信开发微信朋友圈推广

深圳网站建设微信开发,微信朋友圈推广,网站建设框架模板,b2c网站功能前言 最近在和其他软件联合做一个本地图片选择传输功能,为此希望图片能够有序的呈现在客户端,简单的实现了一下功能,通过Mvvm模式进行呈现,过程简单通俗,话不多说直接上图。 处理过程 前台代码 你只需要粘贴到你的前台…

前言

        最近在和其他软件联合做一个本地图片选择传输功能,为此希望图片能够有序的呈现在客户端,简单的实现了一下功能,通过Mvvm模式进行呈现,过程简单通俗,话不多说直接上图。

处理过程

 前台代码

  1. 你只需要粘贴到你的前台xml中就可以,位置记得调整下Margin,我这是按照我的位置进行调整的,所以针对ListBox在你的前台你还需要调整下。
    <ListBox Name="lstFileManager" Background ="Transparent" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" Margin="69,192,50,40"><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel/></ItemsPanelTemplate></ListBox.ItemsPanel><ListBox.ItemTemplate><DataTemplate><!--这里修改内容整体大小以及在你框内的占比,我这一行显示5个--><Grid Margin="17" Width="100" Height="155"><Grid.RowDefinitions><RowDefinition Height="Auto" ></RowDefinition><RowDefinition Height="Auto" ></RowDefinition><RowDefinition Height="Auto" ></RowDefinition></Grid.RowDefinitions><Image Source="{Binding Pic}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100"/><Border BorderThickness="1" BorderBrush="red" Margin="1,107,1,0"/><TextBlock Text="{Binding Name}" Grid.Row="1" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Height="Auto" TextWrapping="Wrap"/></Grid></DataTemplate></ListBox.ItemTemplate>
    </ListBox>

后台代码

  1. 创建一个类进行数据绑定
        public class LVData{public string Name { get; set; }public BitmapImage Pic { get; set; }}
  2. 定义一个集合进行数据缓存 (集合定义在MainWindow的类中)
    ObservableCollection<LVData> LVDatas = new ObservableCollection<LVData>();
  3. 在我们的逻辑中进行数据填充和呈现,清除集合清空ListBox中的Item显示
    //添加图
    LVDatas.Add(new LVData { Name = "图片在ListBox中显示的名称(建议直接显示图片名称)", Pic = new BitmapImage(new Uri("完整的图片路径")) });
    //显示在ListBox中
    lstFileManager.ItemsSource = LVDatas;
    //清除集合清空呈现
    LVDatas.Clear();
    //当前点击的图片名称(lstFileManager.SelectedIndex  这是目前点击的下标)
    Console.WriteLine(LVDatas[lstFileManager.SelectedIndex].Name);
  4. 整体代码
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.IO;
    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 ImageTexture
    {/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{//定义集合ObservableCollection<LVData> LVDatas = new ObservableCollection<LVData>();public MainWindow(){InitializeComponent();ImageTexture2DView("E:\\ProjectFiles\\ImageTexture");}private void ImageTexture2DView(string path){//Path是图片所在的文件夹路径var apps = System.IO.Directory.GetFiles(path);List<string> images = new List<string>();foreach (string app in apps)//---遍历文件夹所有文件{var fi = new FileInfo(app);//---使用FileInfo类进行操作if (fi.Extension == ".png"){//将图片添加到LVData中LVDatas.Add(new LVData { Name = fi.Name.Remove(fi.Name.LastIndexOf(".")), Pic = new BitmapImage(new Uri(fi.FullName)) });}}//进行呈现lstFileManager.ItemsSource = LVDatas;}private void ImageClear_Click(object sender, RoutedEventArgs e){//清除集合清空ListBox中的Item显示LVDatas.Clear();}}public class LVData{public string Name { get; set; }public BitmapImage Pic { get; set; }}
    }
    

结局    

后续想从数据库或者其他地方添加就根据自己的想法添加就可以了,另外获取点击的是哪个绑定个监听事件就可以了,希望对大家有帮助。

http://www.hkea.cn/news/478214/

相关文章:

  • 视频网站制作广告代理公司
  • wordpress主题域名授权密钥生成镇海seo关键词优化费用
  • 北京东直门+网站建设汕头seo外包平台
  • 长沙 做网站企业网络组网设计
  • 北京哪家做网站优化产品seo基础优化
  • 招商加盟网站建设百度网址安全检测
  • 知名做网站费用2024年将爆发新瘟疫
  • 河北省城乡与建设厅网站企业关键词排名优化哪家好
  • 网站开发合同协议百度百科推广费用
  • 推荐黄的网站产品推广策划
  • 济南网站建设设计公司线上运营推广
  • 小清新 wordpressseo排名是什么意思
  • 从客户—管理者为某一公司做一份电子商务网站管理与维护的方案自媒体是如何赚钱的
  • 黑龙江住房和城乡建设厅网站首页每日精选12条新闻
  • 做网站工作都包括什么企业网站搭建
  • 自己可以进行网站建设吗河北网站推广
  • 网站建设与管理论文seo整站怎么优化
  • 西安做网站收费价格网站流量监控
  • 福州网站制作有限公司南京疫情最新情况
  • 国外品牌设计网站天津疫情最新消息
  • 宁波有做网站的地方吗seo报价单
  • 深圳企业网站开发中国法律服务网app最新下载
  • 大连企业网站建站国外域名注册网站
  • 站长工具seo综合查询权重百度在线搜索
  • 伊犁网站建设评价怎样才能上百度
  • 房地产网站建设方案百度实名认证
  • 做外贸可以在哪些网站注册网络项目免费的资源网
  • 中国建设银行信用卡网站首页青岛关键词优化平台
  • 阿里云网站建设考试题目长沙网站推广服务公司
  • 甘肃建设项目审批权限网站俄罗斯搜索引擎yandex官网入口