How to load ItemsSource before setting SelectedItem in ListView?

[亡魂溺海] 提交于 2019-12-02 05:11:57

Firstly you can try to type your ItemsSource in codebehind. You have to add an UserLoaded property in your xaml file to do this. But maybe we need to see your codebehind and viewmodel. Anyway you should try to change your SelectedValue binding mode OneWay to the TwoWay.

After that you should watch your binding style. You have to complete most of your development progress in your viewmodel, and after that you could just call your viewmodel from your xaml codebehind (.cs) with get-set. So, you will have a very clean binding structure.

In this way you can type as follows instead of yours,

    SelectedValue="{Binding Model.BlaBla, Mode=TwoWay}"

in here Model is defined and called in your codebehind of xaml file (.cs). For example in top of your public sealed partial class

    public YourViewModelName Model { get; set; }

and in the same file public YourXamlName()

    Model = new YourViewModelName();

It is a quickly answer and I am not sure. But you should give a shot.

Good luck.

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