Set ItemsSource of Control to another control'

2019-03-30 17:29发布

I am building a UWP Windows 10 App. In a Page I have a FlipView that has static items. Instead of binding them to an ItemsSource, it was easier to set them in Xaml as:

<FlipView x:Name="myFlipView">
<FlipViewItem>...</FlipViewItem>
<FlipViewItem>...</FlipViewItem>
</FlipView>

I want to add an Indicators Control to this FlipView as in this tutorial: http://blog.jerrynixon.com/2014/04/lets-code-build-your-own-flipview-page.html

When I want to set the ItemsSource of my <ItemsControl x:Name="Indicators">I want to set it to the FlipView's ItemsSource. I tried setting it in code as Indicators.ItemsSource = myFlipView.ItemsSource; but it is empty as it is set statically in Xaml. Any idea how to do that?


Edit:

I have used a GridView instead of an ItemsControl since ItemsControl doesn't have a SelectedIndex property like mentioned here: flipView and Page indicator UWP

I set it like that:

<GridView x:Name="Indicators" ItemsSource="{Binding ItemsSource, ElementName=myFlipView}" SelectedIndex="{Binding SelectedIndex, ElementName=myFlipView}">...</GridView>

But it is crashing and throws an Unhandled Exception that I can't catch.

0条回答
登录 后发表回答