2 using System.Collections.Generic;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Media.Animation;
13 using System.Windows.Shapes;
14 using System.Threading;
19 namespace FileNameChenger
22 /// WorkView.xaml の相互作用ロジック
24 public partial class WorkView : Window
27 //Timer stateTimer = null;
28 System.Windows.Forms.Timer stateTimer = null;
31 InitializeComponent();
34 //this.Content = FileNameChenger.Properties.Resources.LineageII.darkelf;
35 //BitmapImage myBitmapImage = new BitmapImage();
36 //myBitmapImage.StreamSource = FileNameChenger.Properties.Resources.LineageII.darkelf.;
38 string[] files = Directory.GetFiles(@".\img", "*.jpg", SearchOption.AllDirectories);
41 BitmapImage myBitmapImage = new BitmapImage();
43 if (files.Length == 0)
45 myBitmapImage.BeginInit();
46 myBitmapImage.UriSource = new Uri(@"FileNameChenger.ico", UriKind.RelativeOrAbsolute);
47 myBitmapImage.EndInit();
51 Random r = new Random();
52 int index = r.Next(files.Length - 1);
53 myBitmapImage.BeginInit();
54 myBitmapImage.UriSource = new Uri(@"file://" + Directory.GetCurrentDirectory() + files[index], UriKind.RelativeOrAbsolute);
55 myBitmapImage.EndInit();
58 imageWork.Source = myBitmapImage;
61 //imagStoryboard.Storyboard.Stop();
62 progressBarWork.Minimum = 0;
63 progressBarWork.Maximum = 100;
66 AutoResetEvent autoEvent = new AutoResetEvent(false);
68 // Create the delegate that invokes methods for the timer.
69 TimerCallback timerDelegate =
70 new TimerCallback(CheckStatus);
74 new Timer(timerDelegate, autoEvent, 1000, 250);
76 stateTimer = new System.Windows.Forms.Timer();
77 stateTimer.Interval = 1000;
78 stateTimer.Tick += new EventHandler(stateTimer_Tick);
83 public override ~WorkView()
85 if (stateTimer != null)
92 void stateTimer_Tick(object sender, EventArgs e)
94 //throw new NotImplementedException();
97 workingImage.Angle = angle;
100 lock (progressBarWork)
102 progressBarWork.Value = angle;
106 public void CheckStatus(Object stateInfo)
110 workingImage.Angle = angle;
113 lock (progressBarWork)
115 progressBarWork.Value = angle;
122 DoWorkingEvent += new EventHandler<EventArgs>(WorkView_DoWorkingEvent);
125 ThreadStart threadDelegate = new ThreadStart(DoWork);
126 Thread newThread = new Thread(threadDelegate);
132 NameScope.SetNameScope(this, new NameScope());
134 this.Title = "Fading Rectangle Example";
135 StackPanel myPanel = new StackPanel();
136 myPanel.Margin = new Thickness(10);
138 Rectangle myRectangle = new Rectangle();
139 myRectangle.Name = "myRectangle";
140 this.RegisterName(myRectangle.Name, myRectangle);
141 myRectangle.Width = 100;
142 myRectangle.Height = 100;
143 myRectangle.Fill = Brushes.Blue;
145 DoubleAnimation myDoubleAnimation = new DoubleAnimation();
146 myDoubleAnimation.From = 1.0;
147 myDoubleAnimation.To = 0.0;
148 myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
149 myDoubleAnimation.AutoReverse = true;
150 myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
152 myStoryboard = new Storyboard();
153 myStoryboard.Children.Add(myDoubleAnimation);
154 Storyboard.SetTargetName(myDoubleAnimation, myRectangle.Name);
155 //Storyboard.SetTargetName(myDoubleAnimation, imageWork.Name);
156 Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.OpacityProperty));
158 // Use the Loaded event to start the Storyboard.
159 myRectangle.Loaded += new RoutedEventHandler(myRectangleLoaded);
160 //imageWork.Loaded += new RoutedEventHandler(myRectangleLoaded);
162 myPanel.Children.Add(myRectangle);
163 //myPanel.Children.Add(imageWork);
164 this.Content = myPanel;
168 StackPanel myStackPanel = new StackPanel();
169 myStackPanel.Margin = new Thickness(20);
172 // Create and set the Button.
173 Button aButton = new Button();
174 aButton.Content = "A Button";
176 // Animate the Button's Width.
177 DoubleAnimation myDoubleAnimation = new DoubleAnimation();
178 myDoubleAnimation.From = 75;
179 myDoubleAnimation.To = 300;
180 myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
181 myDoubleAnimation.AutoReverse = true;
182 myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
184 // Apply the animation to the button's Width property.
185 aButton.BeginAnimation(Button.WidthProperty, myDoubleAnimation);
187 // Create and animate a Brush to set the button's Background.
188 SolidColorBrush myBrush = new SolidColorBrush();
189 myBrush.Color = Colors.Blue;
191 ColorAnimation myColorAnimation = new ColorAnimation();
192 myColorAnimation.From = Colors.Blue;
193 myColorAnimation.To = Colors.Red;
194 myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(7000));
195 myColorAnimation.AutoReverse = true;
196 myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
198 // Apply the animation to the brush's Color property.
199 myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
200 aButton.Background = myBrush;
202 // Add the Button to the panel.
203 myStackPanel.Children.Add(aButton);
204 this.Content = myStackPanel;
208 //imagStoryboard.Storyboard.Begin(this);
209 //imagStoryboard.Storyboard.Stop(this);
210 //imagStoryboard.Storyboard.Pause(this);
214 private Storyboard myStoryboard;
215 private void myRectangleLoaded(object sender, RoutedEventArgs e)
217 myStoryboard.Begin(this);
223 void WorkView_DoWorkingEvent(object sender, EventArgs e)
225 //throw new NotImplementedException();
229 workingImage.Angle++;
236 bool IsCancel = false;
237 private void DoWork()
241 OnDoWorkingEvent(new EventArgs());
246 public event EventHandler<EventArgs> DoWorkingEvent;
247 protected virtual void OnDoWorkingEvent(EventArgs e)
249 EventHandler<EventArgs> handler = DoWorkingEvent;
257 private void buttonCancel_Click(object sender, RoutedEventArgs e)
262 private void buttonRun_Click(object sender, RoutedEventArgs e)
269 private void imageWork_Loaded(object sender, RoutedEventArgs e)
271 imagStoryboard.Storyboard.Stop(this);
274 private void buttonStop_Click(object sender, RoutedEventArgs e)
276 imagStoryboard.Storyboard.Stop(this);