Set ItemsSource of Control to another control's ItemsSource that is Static and set in Xaml

你。 提交于 2020-01-01 06:15:48

问题


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.

来源:https://stackoverflow.com/questions/37423498/set-itemssource-of-control-to-another-controls-itemssource-that-is-static-and-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!