如何以编程方式更改XAML C#Windows应用程序中控件的ScaleY RenderTransform?

如何以编程方式更改XAML C#Windows应用程序中控件的ScaleY RenderTransform?,c#,xaml,animation,visual-studio-2015,C#,Xaml,Animation,Visual Studio 2015,我有以下xaml代码的几个实例。本质上,它是一组网格,以小(24像素高)的状态显示在堆栈面板中,显示一行文本块。当您单击箭头图像(或者更确切地说是图像周围的边框,因为图像中有透明度)时,网格将展开以显示其中的所有细节。我总共有15个: <Grid x:Name="borLecSec1" Style="{StaticResource SearchedSectionGrid}"> <TextBlock x:Name="txtLecSec1" Style="{StaticRe

我有以下xaml代码的几个实例。本质上,它是一组网格,以小(24像素高)的状态显示在堆栈面板中,显示一行文本块。当您单击箭头图像(或者更确切地说是图像周围的边框,因为图像中有透明度)时,网格将展开以显示其中的所有细节。我总共有15个:

<Grid x:Name="borLecSec1" Style="{StaticResource SearchedSectionGrid}">
    <TextBlock x:Name="txtLecSec1" Style="{StaticResource SearchedSectionText}" 
               PointerEntered="SearchSectionEntered" PointerExited="SearchSectionExited" 
               Tapped="SearchSectionTapped"/>

    <Border x:Name="backArrowSection_Lec_1" Style="{StaticResource ExpandSectionButton}" 
            PointerEntered="backArrowSectionEnter" PointerExited="backArrowSectionExit" 
            Tapped="backArrowSectionTapped">

        <Image x:Name="arrowSection_Lec_1" Style="{StaticResource ExpandSectionImage}">
            <Image.RenderTransform>
                <CompositeTransform ScaleY="1"/>
            </Image.RenderTransform>
        </Image>

    </Border>
</Grid>
代码的折叠部分与后面的else非常相似。Stop()命令是必需的,因为如果它们不在那里,我会得到一个错误,说明在重新定位之前必须停止根情节提要。所以我所说的一切都很好。不起作用的是,如果我展开第一个网格,那么arrowSection_Lec_1的缩放比例为-1,如果我展开第二个网格,使arrowSection_Lec_2的缩放比例也为-1,则第一个图像恢复为缩放比例为1,即使其对应的网格仍然展开

我想到的解决方案是让故事板完成事件显式地设置相应箭头的刻度,这样即使为不同的箭头再次运行故事板,它也会保持此位置。我不知道如何在C#中引用此属性


因此,为了清楚起见,我的问题是如何将arrowSection_Lec_1的ScaleY变换从代码隐藏设置为-1?

以下是如何从代码隐藏访问比例:

var transform = (CompositeTransform)arrowSection_Lec_1.RenderTransform;
transform.ScaleY = -1;

谢谢工作得很有魅力。
if (working_grid.Height == 24)
{
    System.Diagnostics.Debug.WriteLine("expand");
    working_grid.Height = double.NaN;

    SearchSectionArrowCollapse.Stop();
    SearchSectionArrowExpand.Stop();

    Storyboard.SetTargetName(SearchSectionArrowExpand, working_image_name);
    SearchSectionArrowExpand.Begin();
}
var transform = (CompositeTransform)arrowSection_Lec_1.RenderTransform;
transform.ScaleY = -1;