我目前有以下 XAML 代码,但是当我运行我的应用程序时,会出现 ScrollBars 但我无法滚动浏览图像列表(滚动条不起作用)。
<Window x:Class="WPFMediaManager.MoviePanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MoviePanel" Height="1024" Width="1473.254" WindowStartupLocation="CenterScreen">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<WrapPanel>
<Image Width="200" Height="300" Stretch="Fill" Source="{Binding}"/>
<TextBlock Text="{Binding}"/>
</WrapPanel>
</DataTemplate>
</Window.Resources>
<Grid x:Name="movie_grid">
<ListView Grid.Row="4" Name ="MovieListView" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Path = movie_posters_list}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
<TextBlock Name="SampleTextBlock" Text="{Binding Path=movie_names}" DataContext="{StaticResource ItemTemplate}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我不确定是什么导致了这个问题,以及我是否使用适当的容器来存放图像。
我的目标类似于以下布局:

背后的 C# 代码:
namespace WPFMediaManager {
/// <summary>
/// Interaction logic for MoviePanel.xaml
/// </summary>
public partial class MoviePanel : Window {
public …Run Code Online (Sandbox Code Playgroud) 我在非活动类中声明了一个哈希映射,如下所示:
public class Wifi {
HashMap<String, String> AccessPoints = new HashMap<String, String>();
AccessPoints.put("AP1", "first_ap");
public ArrayList<Integer> scanWifi(Context context) {
// code here
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试将数据添加到哈希映射中,但我在Android Studio中收到"无法解析符号"错误.
当我放在类AccessPoints.put("AP1", "first_ap");中的一个函数中时,它似乎工作.
我目前正在使用a custom list adapter并在运行时修改listview的行(更改文本,按钮等).
我想找到一种方法来保存/恢复listview在运行时创建的更改,当我启动另一个片段然后返回到包含listview的片段时.
目前,每次都会重新加载列表视图,并且所有运行时更改都将丢失.
以下显示了我如何设置列表适配器.
public void setAdapterToListView(ArrayList<item> list) {
ItemList = list;
ItemAdapter adapter = new MenuItemAdapter(list, getActivity(), this);
ItemListView.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
然后我使用自定义列表适配器在运行时进行更改(如上所述).以下是我在运行时如何更改内容的片段:
if (holder.qty.getText().toString().equals("Qty")) {
relativeLayout.setBackgroundColor(row.getResources().getColor(R.color.navDrawerL ightBlue));
holder.qty.setText("1");
holder.qty.startAnimation(anim);
holder.removeItem.setBackgroundResource(R.drawable.remove_item_red);
holder.removeItem.setEnabled(true);
...
Run Code Online (Sandbox Code Playgroud)
有没有推荐的方法来解决这个问题?