Master / Details绑定MVVM

时间:2018-05-09 13:40:45

标签: mvvm binding uwp master-detail

我有一些问题,我的文件夹与图像正确绑定到掌握详细信息和其他操作。 所以,我有文件夹和图像的模型

public class AppFolder
{
    private long id;
    private List<AppImage> appImages;

    public AppFolder() { }

    public List<AppImage> AppImages { get => appImages; set => appImages = value; }
    public long Id { get => id; set => id = value; }
}

public class AppImage
{
    private int id;
    private string title;
    private ImageSource appImageURL;

    public AppImage() { }
    public AppImage(string title, ImageSource imageSource)
    {
        Title = title;
        AppImageURL = imageSource;
    }
    public int Id { get => id; set => id = value; }
    public string Title { get => title; set => title = value; }
    public ImageSource AppImageURL { get => appImageURL; set => appImageURL = value; }

}

我将List绑定到Master / Details。

    public class UserPhotosViewModel : ViewModelBase
{
    private readonly IDataService dataService;
    private readonly INavigationService navigationService;

    public UserPhotosViewModel(IDataService dataService, INavigationService navigationService)
    {
        this.dataService = dataService;
        this.navigationService = navigationService;

        Initialize();

    }

    private async Task Initialize()
    {         
        var item = new List<AppFolder>();
        try
        {
            item = await dataService.GetDataList();
            FolderList = item;
        }
        catch (Exception ex)
        {
        }      
    }

    private List<AppFolder> folderList;
    public List<AppFolder> FolderList
    {
        get { return folderList; }
        set
        {
            folderList = value;
            RaisePropertyChanged(nameof(FolderList));

        }
    }
}

示例xaml文件

    <controls:MasterDetailsView ItemsSource="{Binding FolderList}">
            <controls:MasterDetailsView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Id}"></TextBlock>
                </DataTemplate>
            </controls:MasterDetailsView.ItemTemplate>

            <controls:MasterDetailsView.DetailsTemplate>
                <DataTemplate>
                    <controls:AdaptiveGridView ItemsSource="{Binding AppImages}"
                                                OneRowModeEnabled="False"
                                                       ItemHeight="205"                                                      
                                                       DesiredWidth="205"     
                                                       SelectionMode="Multiple"     

                                                       Margin="0 6 0 0"    
                                               >
                        <controls:AdaptiveGridView.ItemTemplate>
                            <DataTemplate >
                                <Grid Background="White" Margin="10">
                                    <Image                                                   
                                            Source="{Binding AppImageURL}"                 
                                            HorizontalAlignment="Center"                  
                                            VerticalAlignment="Center"
                                            Stretch="Uniform"
                                            />
                                    <TextBlock Text="{Binding TextTitle}"></TextBlock>
                                </Grid>
                            </DataTemplate>
                        </controls:AdaptiveGridView.ItemTemplate>
                    </controls:AdaptiveGridView>
                </DataTemplate>
            </controls:MasterDetailsView.DetailsTemplate>
        </controls:MasterDetailsView>

所以,它的工作正确,我在页面上看到了带有图像的文件夹 enter image description here

看起来很好,我想一切。 但是当我想从MVVM模型向AdaptiveGridView添加event和SelectedItem时,我发现它并没有看到它们。 Visual Studio告诉我,我可以在Model&#34; AppFolder&#34;中编写它们。但它是不可见的....

所以,我的问题:如何从UserPhotosViewModel向自适应网格添加事件(绑定命令/方法)?

感谢您的时间。

UPDATE enter image description here

0 个答案:

没有答案