c# - 如何在 Windows Phone Silverlight 中获取 UIElement 的角度?

标签 c# xaml silverlight windows-phone-8

我被这段代码困住了,我找不到如何在后面的代码中获取这个 Path 元素的角度,请帮助我!我的目的是在其父元素“CamGrid”旋转时检查“vectorCapture”的角度。十分感谢! 这是我的 XAML 代码:

    <phone:PhoneApplicationPage.Resources>
    <Storyboard x:Name="RotateCamera" RepeatBehavior="Forever">
        <DoubleAnimation 
            Duration="0:0:10" To="360"
            Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
            Storyboard.TargetName="CamGrid"
            d:IsOptimized="True" />
    </Storyboard>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid Name="CamGrid"
          RenderTransformOrigin=".5, .5">
        <Grid.RenderTransform>
            <CompositeTransform x:Name="CamGridCompositeTransform" />
        </Grid.RenderTransform>
        <Path Data="M4,16h1.6V5.6H16V4H4V16z M5.6,27.2H4v12h12v-1.6H5.6V27.2z M37.6,16h1.6V4h-12v1.6h10.4V16z M9.6,20.8H0v1.6
    h9.6V20.8z M20.8,43.2h1.6v-9.6h-1.6V43.2z M37.6,37.6H27.2v1.6h12v-12h-1.6V37.6z M20.8,9.6h1.6V0h-1.6V9.6z M33.6,20.8v1.6h9.6
    v-1.6H33.6z M33.6,20.8"
              Name="vectorCapture"
              Fill="{Binding Path=LocalizedResources.ForeColor2,
            Source={StaticResource LocalizedStrings}}"
              Stroke="{Binding Path=LocalizedResources.ForeColor2,
            Source={StaticResource LocalizedStrings}}"
              StrokeThickness="2"
              Height="64"
              Width="64"
              Margin="0,0,0,0"
              Stretch="Uniform"
              VerticalAlignment="Bottom"/>
    </Grid>
</Grid>

最佳答案

我解决了我的问题,这是我的解决方案:

CompositeTransform CamCT = new CompositeTransform();
CamCT = (CompositeTransform)CamGrid.RenderTransform;
//then get angle by CamCT.Rotation

关于c# - 如何在 Windows Phone Silverlight 中获取 UIElement 的角度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32940058/

相关文章:

c# - 拖放选定的项目作为列表框返回null

c# - 当我尝试将全局样式应用于 Xamarin Forms 中的自定义 ContentView 时出现 NullReferenceException

c# - 如何获取唯一对象引用作为列表中项目的字符串

c# - Silverlight 的鸭子类型(duck typing)库?

c# - 避免 SQL 事务中的死锁

javascript - 无法在 MVC 中捆绑 jQuery 文件

c# - 将字符指针从 C# 传递到 C++

c# - 将 Pervasive SQL 转储到文件并导入到 MySQL

xaml - xaml 中的逻辑 NOT

silverlight - 从代码隐藏添加图像 silverlight hovereffect