2011/08/04

VSPaste

Windows Live Writer に Visual Studio のソースコードをコピペできるプラグインがあったので入れてみた。

MainWindow.xaml

<Window x:Class="DiskView.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListView Name="listView1">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Drive" Width="80">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Label Content="{Binding Path=Name}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn x:Name="UseColumn" Header="Use" Width="150" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid Width="{Binding ElementName=UseColumn, Path=Width}">
                                    <ProgressBar Margin="0,0,12,0" Maximum="100" Value="{Binding Path=Percentage}" Foreground="{Binding Path=Color}" />
                                    <TextBlock Margin="0,0,12,0" Text="{Binding Path=ProgressText}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn x:Name="FreeColumn" Header="Free" Width="150">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid Width="{Binding ElementName=FreeColumn, Path=Width}">
                                    <Label Margin="0,0,12,0" Content="{Binding Path=Free}" HorizontalAlignment="Right" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            <ListViewItem />
        </ListView>
    </Grid>
</Window>

 

MainWindow.xaml.cs

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.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace DiskView
{
    /// <summary>
    /// MainWindow.xaml のI相?互Y作i用pロ?ジWッbクN
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var action = new Action(() =>
            {
                listView1.Items.Clear();
                listView1.Items.Add(new ListItem(new DriveInfo("C")));
                listView1.Items.Add(new ListItem(new DriveInfo("D")));
                listView1.Items.Add(new ListItem(new DriveInfo("E")));
            });
            action.Invoke();

            var timer = new System.Timers.Timer();
            timer.Elapsed += new System.Timers.ElapsedEventHandler((x, y) =>
            {
                Dispatcher.Invoke(action, null);
            });
            timer.Interval = 5000;
            timer.Start();
        }
    }

    public class ListItem
    {
        public string Name { get; set; }
        public int Percentage { get; set; }
        public Brush Color { get; set; }
        public string ProgressText { get; set; }
        public string Free { get; set; }

        public ListItem(DriveInfo di)
        {
            Name = di.Name;
            Percentage = (int)((double)(di.TotalSize - di.TotalFreeSpace) / (double)di.TotalSize * 100);
            if (Percentage > 70)
            {
                Color = Brushes.Yellow;
            }
            else if (Percentage > 90)
            {
                Color = Brushes.DarkRed;
            }
            else
            {
                Color = Brushes.Lime;
            }
            ProgressText = string.Format(
                "{0:F1}%",
                ((double)(di.TotalSize - di.TotalFreeSpace) / (double)di.TotalSize * 100));
            Free = string.Format("{0:F1}MB", di.TotalFreeSpace / 1024.0 / 1024.0);
        }
    }
}

日本語が化けるなぁ

0 件のコメント:

コメントを投稿