方向更改时,ListView不更新

时间:2019-06-13 10:07:14

标签: c# listview xamarin datagrid

我在我的App中以编程方式添加了DataGrid。我有一个事件,该事件在MainDisplayInfo更改时被调用。在这种情况下,我调用函数来创建网格。

Grid grid = this.dataGrid.Children[0] as Grid; // the header 
ContentView view = this.dataGrid.Children[1] as ContentView;
ListView lv = this.dataGrid.Children[2] as ListView;     // the body of the datagrid
lv.ItemsSource = null;
lv.ItemsSource = viewModel.Statistiks;

我要添加标题和列,如下所示:

foreach (var item in zip)
{
    if (IsPortrait)
    {
        cc.Add(new DataGridColumn() { Title = item.Headers, PropertyName = item.Tables, Width = GridLength.Star, HorizontalContentAlignment = LayoutOptions.CenterAndExpand });
    }
    else
        cc.Add(new DataGridColumn() { Title = item.Headers, PropertyName = item.Tables, Width = GridLength.Star, HorizontalContentAlignment = LayoutOptions.CenterAndExpand });
}

我的Itemssource集合如下所示:

private ObservableCollection<StatistikModel> statistiks;
public ObservableCollection<StatistikModel> Statistiks
{
    get { return statistiks; }
    set { statistiks = value; OnPropertyChanged("Statistiks"); }
}

但是当方向更改时,只有页眉可以正确更改,而列表视图则不会更改。

0 个答案:

没有答案