簡體   English   中英

ContentControl不與TextBlock中的文本對齊

[英]ContentControl not aligning with text within a TextBlock

我有一個帶有各種綁定的超鏈接,已將這些綁定放入DataTemplate中,以確保代碼不會重復。 為了使用它,我用ContentTemplate指定一個ContentControl。 但是,將ContentControl內聯與TextBlock文本一起使用會導致鏈接偏移。 我已經確定了以下發生這種情況的測試用例:

<TextBlock>Text with a <ContentControl>Inline content control</ContentControl> in it.</TextBlock>

在此處輸入圖片說明

我發現解決此問題的唯一方法是在ContentControl上指定負的頁邊距,但是顯然這不是理想的,因為當字體大小更改時,它將不起作用。

我認為不可能讓ContentControl的行為與內聯元素相同,而讓ContentControl保持與文本內聯的唯一方法是修改填充/基線等,而該行為無法響應DPI。變化,顯然有點hack。

我使用了Grx70的建議,而是將綁定移動到一種樣式中,然后根據需要在Hyperlink上進行設置:

<Style x:Key="CustomHyperlink" TargetType="{x:Type Hyperlink}" BasedOn="{StaticResource {x:Type Hyperlink}}">
        <Setter Property="NavigateUri" Value="{Binding TheUri}"/>
        <Setter Property="Command" Value="{Binding TheCommand}"/>
        <Setter Property="CommandParameter" Value="{Binding NavigateUri, RelativeSource={RelativeSource Self}}"/>
</Style>

<TextBlock TextWrapping="Wrap">
        ...please <Hyperlink Style="{StaticResource CaseHyperlink}">view in browser</Hyperlink> and...
</TextBlock>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM