Windows phone 7 为什么投影属性为空?
但是:Windows phone 7 为什么投影属性为空?,windows-phone-7,Windows Phone 7,但是:Storyboard.SetTarget(showAnimation,content.Projection)抛出异常。content.Projection为null。这是怎么发生的?您看到的是错误的边框。在您的案例中,项目容器的层次结构类似于Border->ContentControl->ContentPresenter->Border(这是您的)。因此,您必须深入到容器的子层次结构中,才能找到所需的边界 下面的代码递归搜索UIElement的子元素,并给出一些调试输出,以便您可以看到它的
Storyboard.SetTarget(showAnimation,content.Projection)
抛出异常。content.Projection
为null
。这是怎么发生的?您看到的是错误的边框。在您的案例中,项目容器的层次结构类似于Border
->ContentControl
->ContentPresenter
->Border
(这是您的)。因此,您必须深入到容器的子层次结构中,才能找到所需的边界
下面的代码递归搜索UIElement
的子元素,并给出一些调试输出,以便您可以看到它的深度。当找到名为“border”的控件时,它将停止:
很乐意帮忙!如果它解决了你的问题,你可以接受它作为答案:)嘿,ListBox。项目有15个项目,但我只有5个项目,这怎么会发生呢?列表没有为所有项目生成容器,只有可见的项目。哇!我知道。ListBox的ItemsPanel是虚拟化StackPanel,我必须将虚拟化StackPanel更改为StackPanel。谢谢
<ListBox Name="listBoxButtons"
Height="700">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Background="{StaticResource PhoneAccentBrush}"
Name="border"
Width="432" Height="62"
Margin="6" Padding="12,0,0,6">
<TextBlock Text="{Binding}"
Foreground="#FFFFFF" FontSize="26.667"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
<Border.Projection>
<PlaneProjection RotationX="-60"/>
</Border.Projection>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
private void ShowAnim()
{
IEasingFunction quadraticEase = new QuadraticEase { EasingMode = EasingMode.EaseOut };
Storyboard _swivelShow = new Storyboard();
foreach (var item in this.listBoxButtons.Items)
{
UIElement container = listBoxButtons.ItemContainerGenerator.ContainerFromItem(item) as UIElement;
if (container != null)
{
Border content = VisualTreeHelper.GetChild(container, 0) as Border;
if (content != null)
{
DoubleAnimationUsingKeyFrames showAnimation = new DoubleAnimationUsingKeyFrames();
EasingDoubleKeyFrame showKeyFrame1 = new EasingDoubleKeyFrame();
showKeyFrame1.KeyTime = TimeSpan.FromMilliseconds(0);
showKeyFrame1.Value = -60;
showKeyFrame1.EasingFunction = quadraticEase;
EasingDoubleKeyFrame showKeyFrame2 = new EasingDoubleKeyFrame();
showKeyFrame2.KeyTime = TimeSpan.FromMilliseconds(85);
showKeyFrame2.Value = 0;
showKeyFrame2.EasingFunction = quadraticEase;
showAnimation.KeyFrames.Add(showKeyFrame1);
showAnimation.KeyFrames.Add(showKeyFrame2);
Storyboard.SetTargetProperty(showAnimation, new PropertyPath(PlaneProjection.RotationXProperty));
Storyboard.SetTarget(showAnimation, content.Projection);
_swivelShow.Children.Add(showAnimation);
}
}
}
_swivelShow.Begin();
}
private UIElement GetMyBorder(UIElement container)
{
if (container is FrameworkElement && ((FrameworkElement)container).Name == "border")
return container;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(container); i++)
{
var child = (FrameworkElement)VisualTreeHelper.GetChild(container, i);
System.Diagnostics.Debug.WriteLine("Found child "+ child.ToString());
System.Diagnostics.Debug.WriteLine("Going one level deeper...");
UIElement foundElement = GetMyBorder(child);
if (foundElement != null)
return foundElement;
}
return null;
}
Border content = (Border)GetMyBorder(container);