C#技术总结



◆Wpf◆-画面线程委托方法
Dispatcher.Invoke(new Action(ServiceProvider.Configure));
◆Wpf◆-模型数据绑定方法1
ViewModelBase.cs
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace  View
{
    // View model base class
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
ViewModel.cs
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;

namespace View
{

    public class CaptureViewModel : ViewModelBase
    {

        private BitmapSource m_LiveViewImage;   //实时画像显示绑定对象
        private string[] m_ShutterSpeedList;    //快门速度清单
        
        private AsyncObservableCollection<FileItem> m_PictureFiles;
        private int m_BatteryLevel;

        public CaptureViewModel()
        {
            m_LiveViewImage = null;
            m_ShutterSpeedList = null;
            m_SelectedIndex = 0;
            m_IsDeviceLoad = false;
            m_IsCapture = false;
            m_IsLiveViewMode = false;
            m_PictureFiles = new AsyncObservableCollection<FileItem>();
        }

        public AsyncObservableCollection<FileItem> PictureFiles
        {
            get { return m_PictureFiles; }
            set
            {
                m_PictureFiles = value;
                OnPropertyChanged("PictureFiles");
            }
        }
    }
}
MainWindow.xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="View.MainWindow"
        xmlns:local="clr-namespace:View"
        WindowStartupLocation="CenterScreen"
        Title="1" Closed="Window_Closed" WindowStyle="SingleBorderWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="700" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize" MinHeight="700" MinWidth="900" Icon="/SystemExeName;component/Images/Pic.ico" MaxHeight="700" MaxWidth="900" d:DesignWidth="900">

    <Window.Resources>
        <local:ViewModel x:Key="ViewModel"/>
    </Window.Resources>
    <Grid  DataContext="{StaticResource ViewModel}" Name="CaptureWindow" Initialized="MainWindow_Initialized" Unloaded="MainWindow_Unloaded" MinHeight="650" MinWidth="870">
         <ListBox Grid.Row="1"  VirtualizingStackPanel.IsVirtualizing="True"  Name="ImageListBox" ItemsSource="{Binding PictureFiles, IsAsync=True}" BorderThickness="0" IsSynchronizedWithCurrentItem="True" Focusable="False">



◆文件◆-Zip文件
                string destfile = Path.Combine(Path.GetTempPath(), "error_report.zip");
                if (File.Exists(destfile))
                    File.Delete(destfile);

                using (var zip = new ZipFile(destfile))
                {
                    zip.AddFile(ServiceProvider.LogFile, "");
                    zip.Save(destfile);
                }

◆文件◆-文件确认

                if (File.Exists(destfile))
                    File.Delete(destfile);




◆XML◆-XML分析工具
XmlSerializer mySerializer = new XmlSerializer(typeof (Branding));		
FileStream myFileStream = new FileStream(filename, FileMode.Open,FileAccess.Read,FileShare.Read);		
branding = (Branding) mySerializer.Deserialize(myFileStream);		
myFileStream.Close();		



◆系统◆-Windows地址字符串连接

Path.Combine(“C:”,"Soft", "Set.xml");

◆系统◆-应用程序进程取得

Process.GetCurrentProcess().ProcessName;
◆系统◆-关闭当前应用
Application.Current.Shutdown();



◆线程◆-Task.Factory线程调用方法

Task.Factory.StartNew(Application);

◆WEBService◆-开发测试发布问题解决
问题:当通过浏览器访问接口时提示的错误。

HTTP 错误 404.3 - Not Found

由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。

解决方法:
在控制面板->程序和功能->启用和关闭Windows功能如下选项启用后,解决问题。





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值