我正在关注具有此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>
答案 0 :(得分:1)
将其作为窗口的资源(或其他内容):
<Window.Resources>
<custom:BalloonDecorator x:Key="MyDecorator" Background="{StaticResource MessageOutBackground}" PointerLength="10"
...
</custom:BalloonDecorator>
</Window.Resources>
然后在这样的代码中获取它:
BalloonDecorator myDecorator = FindResource("MyDecorator") as BalloonDecorator;