Leiningen

I seem to be running into a strange bug in applying rendertransform's to custom controls.

I have a custom control that inherits from HeaderedContentControl. I can set the .Content and .Header property in xaml and it works fine. However, I am having trouble with RenderTransforms...

I can apply a RenderTransform through styles (code in orange) to my custom control with no problem -- it will work correctly. However, if I cut and past the same code directly to my declaration (code in yellow), it will not even compile. I get this error:

Code Snippet
Error 4 The tag 'FolderControl.RenderTransfom' does not exist in XML namespace 'clr-namespace:Photobox.CustomControls'.

Here is a portion of the xaml. If I use the code in orange, then it works. If I use the code in yellow instead, it won't compile. Can someone tell me the reason for this, and any potential solution

Thanks in advance!

Code Snippet

<Window x:Class="Photobox.PhotoboxMainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:d="http://schemas.microsoft.com/expression/blend/2006"

xmlns:local="clr-namespace:Photobox"

xmlns:PhotoboxCustomControls="clr-namespace:Photobox.CustomControls"

x:Name="MainWindow"

Title="WPF Photobox"

Width="640" Height="480"

>

<Window.Resources>

<Style TargetType="{x:Type PhotoboxCustomControls:FolderControl}" >

<Setter Property="RenderTransform">

<Setter.Value>

<TransformGroup>

<ScaleTransform ScaleX="4" ScaleY="4"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</< FONT>TransformGroup>

</< FONT>Setter.Value>

</< FONT>Setter>

<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />

</< FONT>Style>

</< FONT>Window.Resources>

<Grid>

<PhotoboxCustomControls:FolderControl x:Name="VisibleFolder" Height="50" Width="50">

<PhotoboxCustomControls:FolderControl.RenderTransfom>

<TransformGroup>

<ScaleTransform ScaleX="4" ScaleY="4"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</< FONT>TransformGroup>

</< FONT>PhotoboxCustomControls:FolderControl.RenderTransfom>

<PhotoboxCustomControls:FolderControl.Content>

<PhotoboxCustomControls:ContactSheetControl />

</< FONT>PhotoboxCustomControls:FolderControl.Content>

</< FONT>PhotoboxCustomControls:FolderControl>

</< FONT>Grid>

</< FONT>Window>



Re: Windows Presentation Foundation (WPF) RenderTransform In Custom Control

Tamir Khason

For me it works fine, the only reason I can assume, that your namespace CustomControls is in the other assembly. If so, you should set assembly in namespace declaration




Re: Windows Presentation Foundation (WPF) RenderTransform In Custom Control

Leiningen

Hi Tamir,

Sorry for not getting back to you sooner. It's not an assembly problem. As I said, declaring the custom controls and setting other settings on them in the declarations work fine. The rendertransform works fine in the styles too. It won't compile when I set the rendertransform on the declaration, though. Very strange. You say you are able to set the rendertransform on the declaration of other custom controls

I created a barebones CustomControl (inheriting from ContentControl) and added it to a new project. I also added the ContentPresenter line to the generic.xaml, and added the nessecary code to the window's xaml... Same problem...the following code won't compile. However, if I move the render transform into a style targeting local:CustomControl, it works perfectly. This seems like a bug to me.

In the window:

Code Snippet

<Window x:Class="CustomControlTest4.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="clr-namespace:CustomControlTest4"

Title="CustomControlTest4" Height="300" Width="300"

>

<Grid>

<local:CustomControl1 Background="Yellow" BorderBrush="Red" BorderThickness="2,2,2,2" >

<local:CustomControl1.RenderTransfom>

<TransformGroup>

<ScaleTransform ScaleX="4" ScaleY="4"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</< FONT>TransformGroup>

</< FONT>local:CustomControl1.RenderTransfom>

<local:CustomControl1.Content>

<TextBlock Text="Hello World" />

</< FONT>local:CustomControl1.Content>

</< FONT>local:CustomControl1>

</< FONT>Grid>

</< FONT>Window>

In the generic.xaml:

Code Snippet

<ResourceDictionary

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="clr-namespace:CustomControlTest4"

>

<Style TargetType="{x:Type local:CustomControl1}">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type local:CustomControl1}">

<Border Background="{TemplateBinding Background}"

BorderBrush="{TemplateBinding BorderBrush}"

BorderThickness="{TemplateBinding BorderThickness}">

<ContentPresenter />

</< FONT>Border>

</< FONT>ControlTemplate>

</< FONT>Setter.Value>

</< FONT>Setter>

</< FONT>Style>

</< FONT>ResourceDictionary>

In the contentControl:

Code Snippet

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

namespace CustomControlTest4

{

public class CustomControl1 : System.Windows.Controls.ContentControl

{

static CustomControl1()

{

//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.

//This style is defined in themes\generic.xaml

DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));

}

}

}

Any ideas