2011-01-10 113 views
0

我正在關注具有此xaml的代碼示例,但是如何以編程方式構造此代碼並將其添加到畫布?如何通過編程方式將文本添加到畫布?

<custom:BalloonDecorator Background="{StaticResource MessageOutBackground}" PointerLength="10" 
CornerRadius="5" Margin="10,0,0,0" 
HorizontalAlignment="left"> 
<Border Background="{StaticResource Hilight}" CornerRadius="5"> 
<Border Background="{StaticResource HilightBottom}" 
CornerRadius="5"> 
<TextBlock Text="Hello" HorizontalAlignment="Left" VerticalAlignment="Top"/> 
</Border> 
</Border> 
</custom:BalloonDecorator> 

回答

1

使它的窗口(或別的東西)的資源:

<Window.Resources> 
    <custom:BalloonDecorator x:Key="MyDecorator" Background="{StaticResource MessageOutBackground}" PointerLength="10" 
    ... 
    </custom:BalloonDecorator> 
</Window.Resources> 

然後讓它在這樣的代碼:

BalloonDecorator myDecorator = FindResource("MyDecorator") as BalloonDecorator; 
+0

但我怎麼能裝飾我的TextBlock編程?像myTextBlock.style = myDecorator; ? – 0x4f3759df 2011-01-10 19:53:20

相關問題