首页 > 编程语言 >C# process open img

C# process open img

时间:2024-08-21 20:28:24浏览次数:8  
标签:get C# System imgPath process Windows using open public

if(System.IO.File.Exists(imgPath))
{
    System.Diagnostics.Process.Start(imgPath);  
}

 

 

//xaml
<Window x:Class="WpfApp261.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:local="clr-namespace:WpfApp261"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="dg" ItemsSource="{Binding BooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                  VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.CacheLength="100" 
                  CanUserAddRows="False" AutoGenerateColumns="False"
                  VirtualizingPanel.CacheLengthUnit="Item"
                  VirtualizingPanel.ScrollUnit="Item"                  
                  VirtualizingPanel.VirtualizationMode="Recycling">
            <behavior:Interaction.Triggers>
                <behavior:EventTrigger EventName="MouseDoubleClick">
                    <behavior:CallMethodAction MethodName="dg_MouseDoubleClick" TargetObject="{Binding}"/>
                </behavior:EventTrigger>
            </behavior:Interaction.Triggers>
            <DataGrid.Columns>
                <DataGridCheckBoxColumn Header="Select" Binding="{Binding IsSelected}"/>
                <DataGridTextColumn Header="Id" Binding="{Binding Id}"/>
                <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                <DataGridTemplateColumn Header="Image">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding ImgUrl}" Width="200" Height="500" RenderOptions.BitmapScalingMode="LowQuality"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
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 WpfApp261
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var vm = new MainVM();
            this.DataContext = vm;
        } 
    }

    public class MainVM : INotifyPropertyChanged
    {
        public MainVM()
        {
            InitData();
        }

        private void InitData()
        {
            BooksCollection = new ObservableCollection<Book>();
            var imgsList = System.IO.Directory.GetFiles(@"../../Images");
            int imgsCount = imgsList.Count();
            for(int i=0;i<1000000;i++)
            {
                BooksCollection.Add(new Book()
                {
                    Id = i,
                    Name = $"Name_{i + 1}",
                    ImgUrl = imgsList[i % imgsCount]
                });
            }
        }

        private ObservableCollection<Book> booksCollection;
        public ObservableCollection<Book> BooksCollection
        {
            get
            {
                return booksCollection;
            }
            set
            {
                booksCollection = value;
                OnPropertyChanged(nameof(BooksCollection));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propName)
        {
            var handler = PropertyChanged;
            if(handler!=null)
            {
                handler?.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }


        public void dg_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var dg = sender as DataGrid;
            if(dg!=null)
            {
                var bk = dg?.SelectedItem as Book;
                if(bk!=null)
                {
                    string imgPath = bk.ImgUrl;
                    if(System.IO.File.Exists(imgPath))
                    {
                        System.Diagnostics.Process.Start(imgPath);  
                    }
                }
            }
        }
    }


    public class Book
    {
        public bool IsSelected { get; set; }
        public int Id { get; set; }
        public string Name { get; set;}
        public string ImgUrl { get; set; }
    }
}

 

标签:get,C#,System,imgPath,process,Windows,using,open,public
From: https://www.cnblogs.com/Fred1987/p/18372428

相关文章

  • Java泛型里的Intersection Type
    IntersectionType直译是叫交集类型,语法:&示例写法publicclassMyClass{publicvoidhello(){System.out.println("hello");}}interfaceMyInteface{//...defaultvoidworld(){Syst......
  • 国内外ChatGPT镜像网站集合【2024-08-21最新】~
     一、GPT4o& &4.0turbo&GPT4omini介绍总有人问我,GPT4o、GPT4.0和GPT3.5有什么区别?国内怎么才能用上,听说很复杂以一张表来表达他们的区别吧GPT3.5、GPT3.5Turbo、GPT4.0均已经被官方放弃维护,也就是说我们其实已经使用不到这几个模型了。目前官方主流开放的模型有GP......
  • 汇总国内外ChatGPT镜像网站集合【2024-08最新】可无限制使用~
     一、GPT4o& &4.0turbo&GPT4omini介绍总有人问我,GPT4o、GPT4.0和GPT3.5有什么区别?国内怎么才能用上,听说很复杂以一张表来表达他们的区别吧GPT3.5、GPT3.5Turbo、GPT4.0均已经被官方放弃维护,也就是说我们其实已经使用不到这几个模型了。目前官方主流开放的模型有GP......
  • A Comparative Study of AI-Generated (GPT-4) and Human-crafted MCQs in Programmin
    文章目录题目摘要引言相关工作数据集MCQ生成提示实验设计结果讨论对教学实践的启示有效性的局限性和威胁结论和未来工作题目编程教育中人工智能生成的(GPT-4)和人类编写的MCQ的比较研究论文地址:https://dl.acm.org/doi/10.1145/3636243.3636256摘要    ......
  • 告别 Coding 噩梦-掌握这10个习惯,成为大数据开发高手
    你是否曾在半夜被一个顽固的bug折磨得睡不着觉?是否因为理解不了复杂算法而感到沮丧?别担心,你并不孤单。作为一名经验丰富的大数据开发者,我深知编程之路上的挫折感。但今天,我要和你分享我是如何在这条充满荆棘的道路上找到突破,最终成长为一名得心应手的编程高手的。前......
  • helm values reference other values
    https://helm.sh/docs/chart_template_guide/yaml_techniques/#yaml-anchorshttps://helm.sh/zh/docs/chart_template_guide/yaml_techniques/#yaml-%E9%94%9A%E7%82%B9 YAMLalsoprovidesahandyfeaturecalled anchors,whichletyoueasilyduplicatecontentacross......
  • conda基础命令学习
    前言本文包括了在windows系统下创建和删除虚拟环境、查看版本等一系列指令,会不定期更新。所有创建的虚拟环境都在envs文件中哦。(base除外)查看conda版本:conda--version创建虚拟环境:condacreate--n环境名python=版本号删除虚拟环境:condaremove-n环境名--all......
  • 「OC」视图控制器的懒加载策略
    「OC」视图控制器的懒加载策略文章目录「OC」视图控制器的懒加载策略懒加载懒加载的优点常见的懒加载实现方法使用懒加载的注意事项控制器的懒加载参考资料懒加载懒加载(LazyLoading)是一种设计模式,其核心思想是在需要时才进行对象的创建或资源的加载,而不是在对象......
  • Blocked aria-hidden on a <input> element because the element that just received fo
    bug查资料找到三种解决方案1.第一种在main.js中加入,然后在报错的组件上加,但我没有解决Vue.directive('removeAriaHidden',{bind(el,binding){letariaEls=el.querySelectorAll('.el-radio__original');ariaEls.forEach((item)=>{item.removeA......
  • 标准IO函数:fprintf和fscanf,fread和fwrite
    1.使用分文件编译,实现注册登录界面,使用fgets,fscanf,fpritnf函数。主函数#include"log.h"intmain(intargc,constchar*argv[]){ intkey; while(1) { printf("**********1.注册**********\n"); printf("**********2.登录**********\n"); printf(&quo......