2016-05-06 4 views
0

だから私は持っている次のコードでXAMLで定義されてFlipView:のDataTemplate内のコントロールを取得します

<FlipView x:Name="carrousel" Height="175" Background="Transparent" Margin="0,20,0,0"> 
    <FlipView.ItemTemplate> 
     <DataTemplate> 
      <Grid> 
       <Rectangle x:Name="profile" Stroke="White" StrokeThickness="0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="175" Height="175" Canvas.ZIndex="1" RadiusX="88" RadiusY="88" Tapped="profile_Tapped"/> 
      </Grid> 
     </DataTemplate> 
    </FlipView.ItemTemplate> 
</FlipView> 

ユーザーが四角形をクリックすると、大きななるために、アニメーション、私はまた、他のすべての長方形をしたいです他のすべてのFlipViewItemもサイズを変更します。どうすればこれを達成できますか?私が試した:

foreach(FlipViewItem fvi in carrousel.Items) 
{ 
    Rectangle g = (fvi.Content as Grid).FindName("profile") as Rectangle; 
    g.Width = double; 
    g.Height = double; 
} 

しかし、私のflipviewはFlipViewItemsが、(明らかに何の.Contentを持っていない)、私はそれにバインドさたカスタムクラスを含んでいないとして、それは動作しません見て。これをどのように機能させることができますか?

+0

の背後にあるコードちょうど私が好奇心旺盛です。コントロール名を調べると、カルーセル効果/コントロールを達成しようとしているようです。これは正しいです? –

+0

私はフリップビューを修正して同様の効果を得ようとしていましたが、失敗してしまいましたので、私はその名前を断念して保存しました。 – user2950509

+0

カルーセルのような効果のためにあなたは[この] https://comentsys.wordpress.com/2015/05/26/windows-10-universal-windows-platform-carousel-control/ [this] http:// stackoverflow .com/questions/35008586/3d-carousel-control-available-for-uwpリファレンス。 –

答えて

0
foreach(var fvi in carrousel.Items) 
{ 
FlipViewItem item=carrousel.ContainerFromItem(fvi); 
var rectangle =FindElementInVisualTree<Rectangle>(item); 



//Or without VisualTreeHelper you can do like what were you trying before 
Rectangle g = (item.Content as Grid).FindName("profile") as Rectangle; 
g.Width = double; 
g.Height = double; 
} 

    private T FindElementInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject 
      { 
       var count = VisualTreeHelper.GetChildrenCount(parentElement); 
       if (count == 0) return null; 

       for (int i = 0; i < count; i++) 
       { 
        var child = VisualTreeHelper.GetChild(parentElement, i); 
        if (child != null && child is T) 
         return (T)child; 
        else 
        { 
         var result = FindElementInVisualTree<T>(child); 
         if (result != null) 
          return result; 
        } 
       } 
       return null; 
      } 
0

この解決策は(私が相対的な結合を管理することができなかったので)解決策です。

<Grid Background="{ThemeResource SystemControlBackgroundListMediumBrush}"> 
    <StackPanel Margin="100,10,10,10"> 
     <FlipView x:Name="carrousel" Height="350" Width="350" Background="Red" Margin="0,20,0,0"> 
      <FlipView.ItemTemplate> 
       <DataTemplate> 
        <Grid> 
         <Rectangle x:Name="profile" Stroke="White" StrokeThickness="1" Fill="Aqua" 
            HorizontalAlignment="Center" VerticalAlignment="Center" 
            Width="{Binding ElementName=RefValueRect, Path=Width, Mode=OneWay}" 
            Height="{Binding ElementName=RefValueRect, Path=Height, Mode=OneWay}" Canvas.ZIndex="1" RadiusX="88" 
            RadiusY="88" Tapped="profile_Tapped"/> 
        </Grid> 
       </DataTemplate> 
      </FlipView.ItemTemplate> 
     </FlipView> 
    </StackPanel> 
    <Rectangle x:Name="RefValueRect" Width="175" Height="175" Visibility="Collapsed" /> 
</Grid> 

private void profile_Tapped(object sender, TappedRoutedEventArgs e) 
{ 
    RefValueRect.Width *= 2; 
    RefValueRect.Height *= 2; 
}