ExpanderView is expanded after page navigation

半城伤御伤魂 提交于 2019-12-03 16:58:49

After debugging the whole code of the ExpanderRT control I was able to solve the problem! It's caused by a bug of the original Expander control which was ported over to WinRT

I found out, that the height of _itemsCanvas in the class ExpanderControl.cs is set via this method:

private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e)
{
    if (null != _itemsCanvas && null != _presenter && IsExpanded)
    {
        _itemsCanvas.Height = _presenter.DesiredSize.Height;
    }
}

This causes that the size of the item container is only applied when the ExpanderView is currently expanded. I simply added the following condition to set the height of the item container to 0 when the ExpanderView is currently not expanded.

else if (null != _itemsCanvas && null != _presenter && !IsExpanded)
{
   _itemsCanvas.Height = 0;
}

I added various improvements to the control to take advantage of new UWP capabilities, so if anyone is interested in a UWP compatible version feel free to contact me.

UPDATE

I created a GitHub Repo for the updated ExpanderControl for UWP

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