2014-02-05 25 views
0

我嘗試渲染可寫入位圖上的某些元素。它適用於渲染文本塊,但不是其他的矩形。爲什麼這樣?wp8 writeablebitmap不渲染

void bm_ImageOpened(object sender, RoutedEventArgs e) 
{ 
     WriteableBitmap wbm = new WriteableBitmap((BitmapImage)sender); 

     TextBlock tb = new TextBlock(); 
     tb.FontSize = 40; 
     tb.Text = "text"; 

     Rectangle rt = new Rectangle(); 
     rt.Width = 50; 
     rt.Width = 30; 
     rt.Fill = new SolidColorBrush(Colors.Red); 

     TranslateTransform tf = new TranslateTransform(); 
     tf.X = 100; 
     tf.Y = 100; 
     wbm.Render(tb, tf); //this works 
     wbm.Render(rt, tf); //this not 

     wbmi.Invalidate(); 
} 

回答

1

您正在嘗試渲染一個高度爲0的Rectangle - 您已將其寬度定義了兩次。

我想它應該看起來像這樣:

rt.Width = 50; 
rt.Height = 30;