UserControl - visualbrush not rendered
-
I am new to wpf. I have created a reflective textblock usercontrol .
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="LogoCreator.ReflectiveTextBlock"
Height="50" Width="189" mc:Ignorable="d">
<UserControl.Resources>
<VisualBrush x:Key="ReflectionBrush" Visual="{Binding ElementName=textBlock}"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock" Grid.Row="0" Margin="0" FontSize="18.667" Text="Sample1" TextWrapping="Wrap" HorizontalAlignment="Left" Background="White"/>
<Rectangle x:Name="Reflection" Grid.Row="1" Margin="0,1,0,-32" RenderTransformOrigin="0.5,0.5" Fill="{DynamicResource ReflectionBrush}"><Rectangle.OpacityMask> <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1"> <GradientStop Color="#7EFFFFFF" Offset="0"/> <GradientStop Offset="0.5"/> </LinearGradientBrush> </Rectangle.OpacityMask> <Rectangle.LayoutTransform> <TransformGroup> <ScaleTransform ScaleX="1" ScaleY="-1"/> </TransformGroup> </Rectangle.LayoutTransform> </Rectangle> </Grid>
</UserControl>
I have the rectangles fill property set to the textblocks visual brush. The problem is when this control is add to the main window canvas, it shows only the text, the reflection is not shown. Is it because the visualbrush resource is within the usercontrol ? How do i solve it ?
-
I am new to wpf. I have created a reflective textblock usercontrol .
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="LogoCreator.ReflectiveTextBlock"
Height="50" Width="189" mc:Ignorable="d">
<UserControl.Resources>
<VisualBrush x:Key="ReflectionBrush" Visual="{Binding ElementName=textBlock}"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock" Grid.Row="0" Margin="0" FontSize="18.667" Text="Sample1" TextWrapping="Wrap" HorizontalAlignment="Left" Background="White"/>
<Rectangle x:Name="Reflection" Grid.Row="1" Margin="0,1,0,-32" RenderTransformOrigin="0.5,0.5" Fill="{DynamicResource ReflectionBrush}"><Rectangle.OpacityMask> <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1"> <GradientStop Color="#7EFFFFFF" Offset="0"/> <GradientStop Offset="0.5"/> </LinearGradientBrush> </Rectangle.OpacityMask> <Rectangle.LayoutTransform> <TransformGroup> <ScaleTransform ScaleX="1" ScaleY="-1"/> </TransformGroup> </Rectangle.LayoutTransform> </Rectangle> </Grid>
</UserControl>
I have the rectangles fill property set to the textblocks visual brush. The problem is when this control is add to the main window canvas, it shows only the text, the reflection is not shown. Is it because the visualbrush resource is within the usercontrol ? How do i solve it ?
Ive solved it by replacing the rectangle with border. And setting the borders background to visualbrush binded to textblock, without using resources. I think the problem was that the visualbrush resource was within the usercontrol. Thank you.