在 FlipView_SelectionChanged 事件中设置 ListView 的 SelectedIndex
Set SelectedIndex of ListView in FlipView_SelectionChanged event
我正在使用 FlipView
构建一个照片应用程序。在 BottomAppBar 中,我放置了所有图像的 ListView
,以便当我在 ListView
中单击它时能够在 FlipView
中查看图像并在 [=] 中显示图像14=], select 在 ListView
中编辑(就像分页)。
在 listView.selectionChanged
事件中,当我 select 在 ListView
中显示图像时,我编写了在 FlipView
中显示图像的代码。这是代码:
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();
int IndicatorIndex = listView.SelectedIndex;
GoToPage(CurrentViewState, IndicatorIndex);
}
private void GoToPage(string CurrentViewState, int IndicatorIndex)
{
if (CurrentViewState == "Portrait")
{
flipView1.SelectedIndex = IndicatorIndex;
}
else if (CurrentViewState == "Landscape")
{
if (IndicatorIndex % 2 == 0)
flipView1.SelectedIndex = IndicatorIndex / 2;
else
{
if (IndicatorIndex == 1)
flipView1.SelectedIndex = 1;
else
flipView1.SelectedIndex = (IndicatorIndex + 1) / 2;
}
}
}
现在我需要根据 flipView.SelectedIndex
更改 listView.SelectedIndex
listView.SelectedIndex = flipView.SelectedIndex
我有一个异常:
An exception of type 'System.ArgumentException' occurred in eBookApp.exe but was not handled in user code. Additional information: Value does not fall within the expected range.
我需要能够在 FlipView
中获得相同的图像 selected,selected 并在 ListView
中滚动它...
代替选择更改事件,更简单的方法是使用数据绑定到 SelectedIndex。
<Page
x:Class="BlankApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BlankApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Margin="100, 100, 0, 0">
<FlipView x:Name="flipView1" Width="500" Height="200" SelectionChanged="flipView1_SelectionChanged">
<Image Source="Assets/Logo.scale-100.png" />
<Image Source="Assets/SmallLogo.scale-100.png" />
<Image Source="Assets/SplashScreen.scale-100.png" />
</FlipView>
<ListView Name="listview1" SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"></ListView>
<TextBlock Text="{Binding Path=SelectedIndex, ElementName=flipView1}" />
</StackPanel>
</Grid>
</Page>
我最终通过添加到我的 FlipView
:
使其工作
SelectedIndex="{Binding Path=SelectedIndex, ElementName=listView1, Mode=TwoWay}"
还有我的ListView
:
SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"
他们两个SelectedIndex
互相指代!
我正在使用 FlipView
构建一个照片应用程序。在 BottomAppBar 中,我放置了所有图像的 ListView
,以便当我在 ListView
中单击它时能够在 FlipView
中查看图像并在 [=] 中显示图像14=], select 在 ListView
中编辑(就像分页)。
在 listView.selectionChanged
事件中,当我 select 在 ListView
中显示图像时,我编写了在 FlipView
中显示图像的代码。这是代码:
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();
int IndicatorIndex = listView.SelectedIndex;
GoToPage(CurrentViewState, IndicatorIndex);
}
private void GoToPage(string CurrentViewState, int IndicatorIndex)
{
if (CurrentViewState == "Portrait")
{
flipView1.SelectedIndex = IndicatorIndex;
}
else if (CurrentViewState == "Landscape")
{
if (IndicatorIndex % 2 == 0)
flipView1.SelectedIndex = IndicatorIndex / 2;
else
{
if (IndicatorIndex == 1)
flipView1.SelectedIndex = 1;
else
flipView1.SelectedIndex = (IndicatorIndex + 1) / 2;
}
}
}
现在我需要根据 flipView.SelectedIndex
listView.SelectedIndex
listView.SelectedIndex = flipView.SelectedIndex
我有一个异常:
An exception of type 'System.ArgumentException' occurred in eBookApp.exe but was not handled in user code. Additional information: Value does not fall within the expected range.
我需要能够在 FlipView
中获得相同的图像 selected,selected 并在 ListView
中滚动它...
代替选择更改事件,更简单的方法是使用数据绑定到 SelectedIndex。
<Page
x:Class="BlankApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BlankApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Margin="100, 100, 0, 0">
<FlipView x:Name="flipView1" Width="500" Height="200" SelectionChanged="flipView1_SelectionChanged">
<Image Source="Assets/Logo.scale-100.png" />
<Image Source="Assets/SmallLogo.scale-100.png" />
<Image Source="Assets/SplashScreen.scale-100.png" />
</FlipView>
<ListView Name="listview1" SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"></ListView>
<TextBlock Text="{Binding Path=SelectedIndex, ElementName=flipView1}" />
</StackPanel>
</Grid>
</Page>
我最终通过添加到我的 FlipView
:
SelectedIndex="{Binding Path=SelectedIndex, ElementName=listView1, Mode=TwoWay}"
还有我的ListView
:
SelectedIndex="{Binding Path=SelectedIndex, ElementName=flipView1, Mode=TwoWay}"
他们两个SelectedIndex
互相指代!