如何在网格上动态重新布局用户控件?

How can I dynamically re-layout user controls on a grid?


如何动态地重新布局我放在网格上的用户控件? 我可以使用 UniformGrid 吗?

像这样在堆栈面板上添加控件

<StackPanel Orientation="Horizontal">
    <TextBlock TextWrapping="NoWrap" FontSize="20" Text="A wonderful serenity has taken possession " Margin="5,0,0,0" Height="35"/>
    <Ellipse Fill="#FFC5FF00" Stroke="Black" Width="25" Height="25" Margin="10,0,0,0"/>
    <TextBlock TextWrapping="NoWrap" FontSize="20" Text="I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine." Margin="10,0,0,0" Height="35"/>
    <Ellipse Fill="#FFC5FF00" Stroke="Black" Width="25" Height="25" Margin="10,0,0,0"/>
    <TextBlock TextWrapping="NoWrap" FontSize="20" Text="I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil" Margin="10,0,0,0" Height="35"/>
</StackPanel>

这就是我得到的

但这就是我想要达到的

考虑使用带有内联 UI 元素的单个 TextBlock:

<TextBlock FontSize="20" TextWrapping="Wrap">
    <Run Text="A wonderful serenity has taken possession"/>
    <Ellipse Fill="#FFC5FF00" Stroke="Black" Width="25" Height="25" Margin="10,0" TextBlock.BaselineOffset="20"/>
    <Run Text="I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine."/>
    <Ellipse Fill="#FFC5FF00" Stroke="Black" Width="25" Height="25" Margin="10,0" TextBlock.BaselineOffset="20"/>
    <Run Text="I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil"/>
</TextBlock>