2011-01-10 109 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

相关问题