Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. UserControl - visualbrush not rendered

UserControl - visualbrush not rendered

Scheduled Pinned Locked Moved WPF
wpfquestioncsharphtmlcss
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeepakMega
    wrote on last edited by
    #1

    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 ?

    D 1 Reply Last reply
    0
    • D DeepakMega

      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 ?

      D Offline
      D Offline
      DeepakMega
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups