【问题标题】:WPF show a control to end of a Dynamic textblockWPF 将控件显示到动态文本块的末尾
【发布时间】:2014-10-20 09:14:04
【问题描述】:

在 WPF 中,我想以一种遵循动态绑定文本块内容的方式显示控件。我使用的 xaml 结构是:

<StackPanel Orientation="Vertical" >
<DockPanel  Margin="2,3">
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Right"> //right side control here
        <Button Tag="{Binding}" Style="{StaticResource ResourceKey=dbokLinkStyle}" Content="delete">
        </Button>
    </StackPanel>     
    <WrapPanel Orientation="Horizontal">
        <TextBlock  TextTrimming="WordEllipsis" TextWrapping="Wrap" Text="{Binding Quote}"  FontWeight="Bold" FontSize="16"  
                    VerticalAlignment="Center" ></TextBlock>
        <Button Tag="{Binding}">
            <StackPanel>
                <TextBlock Text="Page"/>
            </StackPanel>     
        </Button>
    </WrapPanel>                                                        
</DockPanel>
<StackPanel Orientation="Horizontal">
    Row 2 controls..
</StackPanel>

我想在带有绑定引号的文本块之后立即显示页面按钮。但是上面的 xaml 使它总是只在右上角。那么我怎样才能让它跟随文本块控件。 布局更像

【问题讨论】:

  • 你不能有一个水平的stackpanel而不是一个wrappanel吗?
  • 然后我看不到文本块的完整内容,窗口的最大宽度是 800,如果文本块内容超过了?
  • 对不起,我想我理解错了,是你想要的标题页信息旁边的删除按钮吗?
  • 不,我可以设法始终使用停靠面板在右侧显示删除按钮,但我无法使控件以跟随标题的方式显示日期文本。如果我使用stackpanel,标题的长度太大我也看不到控件[因为禁用了水平滚动]
  • 如果标题太长,你可以不截断它,然后在工具提示中显示完整的标题吗?或者如果标题不适合一行,您是否想在多行中显示标题?

标签: c# wpf xaml


【解决方案1】:

用这样的东西替换你的 WrapPanel:-

<TextBlock TextWrapping="Wrap">
  <TextBlock TextTrimming="WordEllipsis" Text="{Binding Foo}" FontWeight="Bold" FontSize="16" VerticalAlignment="Center" />
  <Button Content="Page" />
</TextBlock>

整个 TextBlock 将在其内容(即内部 TextBlock 按钮)过长时换行。

【讨论】:

  • 是的,这与我正在寻找的有点相似。此布局中是否有任何特定规则,因此按钮页面出现在 TextBlock 旁边。原因有时甚至在右边有足够的空间 Button 出现在 Second Line 上,但有时在 TextBlock 本身旁边
  • @JMat 不确定。也许受到某些东西的影响?您可能不想删除 TextTrimming 属性,因为它现在已无关紧要,因为它永远不会被修剪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-21
相关资源
最近更新 更多