2016-09-08 6 views
0

Gitリポジトリ:https://github.com/jimmyt1988/TestXamarinフォーム - プリズムバウンドプロパティ - レンダリング問題


私はデスクトップウィンドウにUWPローカルデバイス上の10のPCを実行している "エミュレータ"


私は深い整数を持っています私のビューモデルのプロパティは、ボタンコマンドによって増分されます。

私がすると、番号が画面から消えて、アプリケーションのサイズを変更すると、再び正しくレンダリングされます。

何が起こっているか

Androidエミュレータで動作するようです。

enter image description here

コード

public DelegateCommand<FoodGroupModel> SubtractFromAmountEatenCommand { get; private set; } 

... 

SubtractFromAmountEatenCommand = new DelegateCommand<FoodGroupModel>((foodGroup) => SubtractFromAmountEaten(foodGroup)); 

... 

public void SubtractFromAmountEaten(FoodGroupModel foodGroup) 
{ 
    if(foodGroup.AmountEaten != 0) 
    { 
     foodGroup.AmountEaten--; 
    } 
} 

... 

public class FoodGroupModel : BindableBase 
{ 
    private int _amountEaten; 
    public int AmountEaten 
    { 
     get { return _amountEaten; } 
     set { SetProperty(ref _amountEaten, value); } 
    } 
} 

XAML:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" 
      prism:ViewModelLocator.AutowireViewModel="True" 
      x:Class="...Views.MealPage"> 

    <StackLayout> 
     <Label Text="{Binding Meal.Number}"/> 
     <ListView x:Name="FoodGroupsListView" ItemsSource="{Binding Meal.FoodGroups}"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <ViewCell> 
         <ViewCell.View> 
          <Grid> 
           <Grid.RowDefinitions> 
            <RowDefinition Height="50"/> 
           </Grid.RowDefinitions> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition Width="1*" /> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition Width="100" /> 
            <ColumnDefinition Width="50" /> 
            <ColumnDefinition Width="50" /> 
           </Grid.ColumnDefinitions> 

           <Label Grid.Row="0" Grid.Column="0" TextColor="#bababa" Text="Group"></Label> 
           <Label Grid.Row="0" Grid.Column="1" Text="{Binding Title}" /> 

           <Label Grid.Row="0" Grid.Column="2" TextColor="#bababa" Text="Qty"></Label> 
           <Label Grid.Row="0" Grid.Column="3" Text="{Binding AmountEaten}" /> 

           <Button Grid.Row="0" Grid.Column="4" 
             Command="{Binding Source={x:Reference FoodGroupsListView}, Path=BindingContext.UndoAmountEatenByOneCommand}" 
             CommandParameter="{Binding}" 
             Text="✖"></Button> 

           <Button Grid.Row="0" Grid.Column="5" 
             Command="{Binding Source={x:Reference FoodGroupsListView}, Path=BindingContext.SubtractFromAmountEatenCommand}" 
             CommandParameter="{Binding}" 
             Text="✔"></Button> 
          </Grid> 
         </ViewCell.View> 
        </ViewCell> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 
    </StackLayout> 

</ContentPage> 
+0

どのような方法でもこの問題を改善できますか? – Jimmyt1988

+0

とにかく私はまだ再現しようとしています。 githubに再生プロジェクトをアップロードするか、どこかでより良いかもしれません。 –

+0

@ Sunteen-MSFT - 私はgithubリポジトリを追加しました - https://github.com/jimmyt1988/Test/tree/master/DailyPlate/DailyPlate – Jimmyt1988

答えて

0

私が行うと、番号が画面からdisapears、その後、私は自分のアプリケーションのサイズを変更する場合、それは正しくagaiをレンダリングしますn。

あなたが問題に遭遇するかもしれません。うまく動作しませんバインディングプロパティの変更通知Xamarin ListViewの内側(が再度レンダリングに関連する可能性がある)、ここでそれを報告してください:Bugzilla

のWindowsランタイム・プラットフォームで(/ WP 8.1 & UWPウィン)は、我々は一時的にこの問題を回避するための回避策を使用する必要があります。

private void RefreashFoodGroupModel() 
     { 
      if (Device.OS == TargetPlatform.Windows || Device.OS == TargetPlatform.WinPhone) 
      { 
       //var index = Meal.FoodGroups.IndexOf(foodGroup); 
       //Meal.FoodGroups.RemoveAt(index); 
       //Meal.FoodGroups.Insert(index, foodGroup); 

       var t = Meal.FoodGroups; 
       Meal.FoodGroups = new System.Collections.ObjectModel.ObservableCollection<FoodGroupModel>(); 
       foreach (var item in t) 
       { 
        Meal.FoodGroups.Add(item); 
       } 
      } 
     } 

は、データ変更後にデータを更新するために、上記のメソッドを呼び出します:

public void SubtractFromAmountEaten(FoodGroupModel foodGroup) 
     { 
      if(foodGroup.AmountEaten != 0) 
      { 
       foodGroup.AmountEaten--; 
       RefreashFoodGroupModel(); 
      } 
     } 

     public void UndoAmountEatenByOne(FoodGroupModel foodGroup) 
     { 
      if (foodGroup.AmountEaten != foodGroup.Quantity) 
      { 
       foodGroup.AmountEaten++; 
       RefreashFoodGroupModel(); 
      } 
     } 

この回避策は、ListViewアイテムの最新表示を引き起こします。

enter image description here

+0

うわー。おかげでマン!どのような恐ろしいバグ。 – Jimmyt1988

+0

@ Jimmyt1988 u r welcome。私の返信はあなたの質問に答えましたか?:)私はこれが間違いなくXamarinのバグだと言っているわけではありません、Xamarinチームはあなたのバグレポートに基づいて根本的な原因を調査します;) –

+0

私は今夜、準備ができたら、遅れて申し訳ありません。もう一度感謝します。確かに何千ものアプリに影響を与えるバグがあるのは間違いです...確かに、これは誰もが報告している重要なものです。 – Jimmyt1988

関連する問題