모방 vs WPF 보기 좋 은 진도 구현

8241 단어 vs진도 표
인터페이스 가 우호 적 이기 위해 서 일반적인 조작 시간 이 비교적 길 때 진도 항목 의 힌트 를 증가 해 야 한다.WPF 자체 진도 가 별로 예 쁘 지 않 고 시각 적 효과 도 없 기 때문이다.나중에 VS 2012 를 설치 할 때 설치 과정 에서 진도 가 좋 은 것 을 발견 하고 인터넷 에서 자 료 를 찾 았 다.ModernUI(오픈 소스),주소:https://github.com/firstfloorsoftware/mui를 배 웠 습 니 다.
나중에 시 도 를 해서 데 모 를 써 봤 는데 효과 가 좋았어 요.또 tif 파일 을 전문 적 으로 녹음 해 효 과 를 볼 수 있 도록 했다.잔말 말고 먼저 효 과 를 보 여 주세요.
효과
A.VS 2012 설치 인터페이스 그림;

B.개인 시도 데모 효과 도:

2.실현 설명
1.MUI 관련 코드 또는 dll 파일 을 다운로드 합 니 다.
2.프로젝트 에서 이 dll 을 도입 하고 자원 파일 을 도입 합 니 다.

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
3.진행 표시 줄 이 필요 한 페이지 에 컨트롤 을 추가 합 니 다(사실은 WPF 컨트롤 입 니 다.MUI 가 스타일 을 확 장 했 을 뿐 입 니 다).

<Label Margin="280,169,0,0" Style="{StaticResource BackGroundContentText}" x:Name="lblMainState" HorizontalAlignment="Left" VerticalAlignment="Top"> :</Label>
        <ProgressBar Margin="280,200,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500" Minimum="0" x:Name="ProgressControlRealValue" Maximum="1"  Value="0.1" Height="16" IsIndeterminate="False"/>
        <Label Margin="280,212,0,0" Style="{StaticResource BackGroundContentText}" x:Name="lblProcess" HorizontalAlignment="Left" VerticalAlignment="Top"> ...</Label>
        <ProgressBar Margin="280,250,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"  Minimum="0" x:Name="ProgressControl"  Width="500" Maximum="2" Height="16" IsIndeterminate="True" />
4.배경 이 실현 되 고 상황 에 따라 진도 문자 와 진도 항목 의 값 을 업데이트 해 야 하기 때 문 입 니 다.그래서 여기 서 비동기 BackgroundWorker 를 사 용 했 습 니 다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Monitor.Class
{
  /// <summary>
  ///     
  /// </summary>
  public class CWorker
  {
    /// <summary>
    ///   
    /// </summary>
    private BackgroundWorker backgroundWorker;

    /// <summary>
    ///        
    /// </summary>
    public Action BackgroundWork { get; set; }

    /// <summary>
    ///            
    /// </summary>
    public event EventHandler<BackgroundWorkerEventArgs> BackgroundWorkerCompleted;

    private BackgroundWorkerEventArgs _eventArgs;//    

    /// <summary>
    ///   
    /// </summary>
    public CWorker()
    {
      _eventArgs = new BackgroundWorkerEventArgs();
      backgroundWorker = new BackgroundWorker();
      backgroundWorker.WorkerReportsProgress = true;
      backgroundWorker.WorkerSupportsCancellation = true;
      backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
      backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
    }

    /// <summary>
    ///     
    /// </summary>
    public void BegionWork()
    {
      if (backgroundWorker.IsBusy)
        return;
      backgroundWorker.RunWorkerAsync();
    }

    /// <summary>
    ///   
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
      if (BackgroundWork != null)
      {
        try
        {
          BackgroundWork();
        }
        catch (Exception ex)
        {
          _eventArgs.BackGroundException = ex;
        }
      }
    }

    /// <summary>
    ///   
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
      if (this.BackgroundWorkerCompleted != null)
      {
        this.BackgroundWorkerCompleted(null, _eventArgs);
      }
    }
  }

  /// <summary>
  ///   
  /// </summary>
  public class BackgroundWorkerEventArgs : EventArgs
  {
    /// <summary>
    ///             
    /// </summary>
    public Exception BackGroundException { get; set; }
  }
}


namespace Monitor
{
  /// <summary>
  /// Splash.xaml      
  /// </summary>
  public partial class Splash : Window
  {
    MainWindow m_MainWindow = null;//   
    CWorker m_Work = null;//  

    public Splash()
    {
      InitializeComponent();
      m_MainWindow = new MainWindow();//       
      m_Work = new CWorker();
      m_Work.BackgroundWork = this.ProcessDo;
      m_Work.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(m_Work_BackgroundWorkerCompleted);
    }

    /// <summary>
    ///     
    /// </summary>
    public void ProcessDo()
    {
      m_MainWindow.InitData(this);
    }

    /// <summary>
    ///   
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      this.DragMove();
    }

    /// <summary>
    ///     
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      m_Work.BegionWork();
    }

    /// <summary>
    ///     
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void m_Work_BackgroundWorkerCompleted(object sender, BackgroundWorkerEventArgs e)
    {
      m_MainWindow.Show();
      this.Close();
    }

    /// <summary>
    ///   
    /// </summary>
    /// <param name="text"></param>
    private delegate void SetProcessLabelDelegate(string text, double processValue);
    public void SetProcessValue(string text, double processValue)
    {
      if (!Dispatcher.CheckAccess())
      {
        Dispatcher.Invoke(DispatcherPriority.Send, new SetProcessLabelDelegate(SetProcessValue), text, processValue);
        return;
      }
      this.lblProcess.Content = text;
      this.ProgressControlRealValue.Value = processValue;
    }
  }
}
이상 에서 말 한 것 이 바로 본문의 전체 내용 이 니 여러분 들 이 좋아 하 시 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기