带有 ImageBrush 作为前景的 UWP 下划线文本块不显示下划线
UWP Underline Textblock with ImageBrush as Foreground does not show the Underline
我正在使用 ImageBrush
作为 Textblock
Foreground
。它工作正常,但是当 Textblock
为 Underline
时,该行不显示。
重现。在 XAML
<TextBlock x:Name="textBlock" FontSize="80" FontWeight="Bold">
<Underline>This is my text</Underline>
</TextBlock>
在代码后面
Uri uri = new Uri("ms-appx:///Assets/0.png");
BitmapImage bmp = new BitmapImage(uri);
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = bmp;
this.textBlock.Foreground = imageBrush;
这是应用了下划线的 SolidColorBrush 的效果
然后当应用ImageBrush
时,下划线消失了
所以我的问题是如何将 ImageBrush
Foreground
应用到 UWP 中的 Underline
Textblock
?
So my question is how do I apply ImageBrush Foreground to an Underline Textblock in UWP?
默认情况下,当 ImageBrush
应用于 TextBlock
的 Foreground
属性.
时,下划线将被删除
解决方法是使用 Border
模拟下划线:
<Border BorderThickness="0, 0, 0, 2" Height="{Binding ActualHeight, ElementName=textBlock}" Width="{Binding ActualWidth, ElementName=textBlock}">
<Border.BorderBrush>
<ImageBrush ImageSource="Assets/0.jpg" />
</Border.BorderBrush>
<TextBlock x:Name="textBlock" FontSize="50" FontWeight="Bold">
<TextBlock.Foreground>
<ImageBrush ImageSource="Assets/0.jpg" />
</TextBlock.Foreground>
<Underline><Run Text="This is my text"/></Underline>
</TextBlock>
</Border>
您可以创建一个 UserControl/CustomControl 以保持可重用性。
您可以像这样使用包装面板制作内联文本
Inline Texts Image
我正在使用 ImageBrush
作为 Textblock
Foreground
。它工作正常,但是当 Textblock
为 Underline
时,该行不显示。
重现。在 XAML
<TextBlock x:Name="textBlock" FontSize="80" FontWeight="Bold">
<Underline>This is my text</Underline>
</TextBlock>
在代码后面
Uri uri = new Uri("ms-appx:///Assets/0.png");
BitmapImage bmp = new BitmapImage(uri);
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = bmp;
this.textBlock.Foreground = imageBrush;
这是应用了下划线的 SolidColorBrush 的效果
然后当应用ImageBrush
时,下划线消失了
所以我的问题是如何将 ImageBrush
Foreground
应用到 UWP 中的 Underline
Textblock
?
So my question is how do I apply ImageBrush Foreground to an Underline Textblock in UWP?
默认情况下,当 ImageBrush
应用于 TextBlock
的 Foreground
属性.
解决方法是使用 Border
模拟下划线:
<Border BorderThickness="0, 0, 0, 2" Height="{Binding ActualHeight, ElementName=textBlock}" Width="{Binding ActualWidth, ElementName=textBlock}">
<Border.BorderBrush>
<ImageBrush ImageSource="Assets/0.jpg" />
</Border.BorderBrush>
<TextBlock x:Name="textBlock" FontSize="50" FontWeight="Bold">
<TextBlock.Foreground>
<ImageBrush ImageSource="Assets/0.jpg" />
</TextBlock.Foreground>
<Underline><Run Text="This is my text"/></Underline>
</TextBlock>
</Border>
您可以创建一个 UserControl/CustomControl 以保持可重用性。
您可以像这样使用包装面板制作内联文本 Inline Texts Image