如何在网格上动态重新布局用户控件?
Posted
技术标签:
【中文标题】如何在网格上动态重新布局用户控件?【英文标题】:How can I dynamically re-layout user controls on a grid? 【发布时间】:2021-09-19 12:13:59 【问题描述】: 如何动态重新布局放在网格上的用户控件? 我可以使用 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>
这就是我得到的
但这就是我想要实现的
【问题讨论】:
【参考方案1】:考虑使用带有内联 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>
【讨论】:
以上是关于如何在网格上动态重新布局用户控件?的主要内容,如果未能解决你的问题,请参考以下文章