0

在 Silverlight 4 中:我将用户控件转换为模板控件。在我的用户控件中,我有一个 RenderTransform

<src:UserControlView.RenderTransform>
    <TransformGroup>
        <ScaleTransform/>
        <SkewTransform/>
        <RotateTransform/>
        <TranslateTransform X="-478" Y="-478"/>
    </TransformGroup>
</src:UserControlView.RenderTransform>

但是现在我在 Controltemplate 中,我收到一条错误消息:

错误 5 在类型“MyControl”中找不到可附加属性“RenderTransform”。...\主题\通用.xaml

                <local:MyControl.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform />
                        <SkewTransform />
                        <RotateTransform />
                        <TranslateTransform X="-478"
                                            Y="-478" />
                    </TransformGroup>
                </local:MyControl.RenderTransform>

local:MyControl 是一次绝望的尝试,因为我不知道如何或在哪里寻找。我的 MyControl 继承自 Control 并且 UIElement 上有一个 RenderTransform 所以它必须以某种方式找到它吗?

4

1 回答 1

2

我假设您只是想设置默认的渲染变换属性?如果是这样,您只想以通用样式实现设置器:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:SilverlightApplication1"
>
    <Style TargetType="local:MyControl">
        <Setter Property="RenderTransform">
            <Setter.Value>
                <TransformGroup>
                    <TranslateTransform X="-478" Y="-478" />
                </TransformGroup>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:MyControl">
                    // Your actual template goes here
                </ControlTemplate>
            </Setter.Value>            
        </Setter>
    </Style>
</ResourceDictionary>

如果不是,请显示更多您当前的源/Xaml,我将更正此示例。

于 2010-09-13T14:29:40.800 回答