目前分類:WPF (6)
- Jun 30 Tue 2015 14:28
[WPF] Xaml泛型
- Jul 06 Sun 2014 19:25
WPF 將邏輯從View搬到ViewModel不使用Command
在MVVM的架構下,通常為了將事件及邏輯從View的code behind(.cs檔)中搬離,會使用到Command,不過Command的建置作業比傳統的事件較為麻煩,在參考Blend 的WPF資料繫結應用程式專案及Google之後,發現不需使用Command而且還能跟原本的事件相容,並且搬移到ViewModel中!
- Nov 20 Wed 2013 11:59
透過Json.Net 快速轉換class to xml與反轉
初始化
Car car = new Car(); car.root = new Root(); car.root.list = new List(); car.root.name = "海德格"; car.root.data = "救我"; for (int f = 0; f < 10; f++) { car.root.list.Add(f.ToString()); }
class to json, then to xml
- Nov 06 Wed 2013 15:53
[WPF] C# 產生DataTemplate
FrameworkElementFactory wrapElement = new FrameworkElementFactory(typeof(WrapPanel)); ItemsPanelTemplate itemPanelDataTemplate = new ItemsPanelTemplate(wrapElement); itemPanelDataTemplate.VisualTree = wrapElement; myListbox = new ListBox() { Opacity = 1, Visibility = System.Windows.Visibility.Visible, Height = double.NaN, Width = double.NaN, ItemsPanel = itemPanelDataTemplate, Background = null, Foreground = null, BorderBrush = null, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 0, 30, 0) };
- Nov 04 Mon 2013 13:01
WPF Tap 事件
- May 08 Sun 2011 14:30
[C#] WPF的高速影像處理
private void button2_Click(object sender, RoutedEventArgs e) { WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage); int startTime = Environment.TickCount; int width = bitmapImage.PixelWidth; int height = bitmapImage.PixelHeight; int stride = width * ((bitmapImage.Format.BitsPerPixel + 7) / 8); byte[] pixel = new byte[height * stride]; writeableBitmap.CopyPixels(pixel, stride, 0); Parallel.For(0, height, y => { int x; for (x = 0; x < stride; x++) { pixel[x + y * stride] = (byte)(255 - pixel[x + y * stride]); } }); writeableBitmap.WritePixels(new Int32Rect(0, 0, width, height), pixel, stride, 0); image1.Source = writeableBitmap; this.Title =(Environment.TickCount - startTime) + " ms"; //CroppedBitmap }
這是WPF對影像做顏色反轉的程式,使用CopyPixels取得每一點的BGRA的byte array之後,用Parallel.For(平行For)進行反轉RGB顏色,然後用WritePixels把處理完後的BGRA array寫回去,然後使用image1顯示出來。