[英]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.