Xamarin iOS tableview issue

1. Cell height not correct:
Call ForceUpdateSize() to update it, however if ListViewCachingStrategy is RecycleElement, height will still be clipped @_@, currently use RetainElement as a work around..

^上面果個唔WORK, FourceUpdateSize應該盡量避免

另外發現拎走ControlTemplate,改用一大塊 StackLayout裝住返果2種template, 再係個stackLayout做datatrigger 轉IsVisible做.

估計係因為ControlTemplate比較大食, 佢計高度果陣計錯左?



最後係用原生IOS + ObservableCollection 既UPDATE做到



https://github.com/xamarin/xamarin-forms-samples/issues/390#issuecomment-439651364
At the beginning I use DataTrigger to represent different state of the cell:

`
Cell

     <Grid>
      <ContentView ControlTemplate = "NormalMessage">
                 <DataTrigger Binding={Binding IsMasked}>
                            <Setter Property="ControlTemplate" Value="MaskedMessage">
                 </DataTrigger>
       </ContentView>
      </Grid>
/Cell`
^Something like that

At the code behind of the cell, i did update the Property {IsMasked} and call ForceUpdateSize, and resulting in the above buggy view.

I followed the fourth method of this post, and made a little changes to my code:
[post](https://forums.xamarin.com/discussion/comment/205764/#Comment_205764)

Instead of using ContentView switching ControlTemplate, I paste both View(NormalMessage and MaskedMessage) in a StackLayout and switching their IsVisible property.

Also Instead of calling ForceUpdateSize, I decided to update the ObservableList ItemsSource like this:
`
var newMsg = JsonConvert.DeserializeObject<Message>(JsonConvert.SerializeObject(sourceMsg));
newMsg.IsMasked = false;

GroupedMessages = newMsg;
`
To trigger the update.

And turn out the result is satisfying! Smooth animation and correct height of the cell! I am not so certain what's going on and am I doing unnecessary stuff, my guess is Switching ContentView ControlTemplate is a bit slower than the height of the cell being calculated, resulting in wrong height of the cell, and also according to the official document
`Developers can call this method to update the cell's size, even if the cell is currently visible. Developers should note that this operation can be expensive.`
Maybe that's why the animation is jitty and why we should avoid it? hmmm



2.Masked Message Image width:
Use time row width:
 WidthRequest="{Binding Path=Width, Source={x:Reference TimeStackLayout}}"

留言

這個網誌中的熱門文章

msdeploy include ApplicationPool setting and ignore recycle time

Invoke generic method