选定项目后,Xamarin.Forms IsVisible无法在Android上运行

时间:2017-11-07 22:33:31

标签: c# android listview xamarin.forms

我有IsVisible的问题。我希望在ListView StackLayout中的选择项目显示标签但选择的项目不起作用后。当然,我有其余的代码。 IsVisible = false它的工作,所以我只有显示信息的问题。我已经尝试了所有更改代码的almsot但不能正常工作。

public new string Title { get; set; }
public string Info { get; set; }
public int Timer { get; set; }

private bool _isVisible = false;
public new bool IsVisible
{
  get => _isVisible;
  set => Set(ref _isVisible, value);
}

  private void Set(ref bool _isVisible, bool value)
  {
     return;
  }

private void DO ()
{
  Task.Factory.StartNew(() =>
{
   ChallengeList.ItemsSource = new List<MainPage>
 {
     new MainPage {Title = "Cuipka", Info="Cipka"},
     new MainPage {Title = "Cuipka", Info="Cipka"},
     new MainPage {Title = "Cuipka", Info="Cipka"},
     new MainPage {Title = "Cuipka", Info="Cipka"},
   };
  });
 }


private void ChallengeList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
    //    if (e.SelectedItem == null)
    //        return;
  if (e.SelectedItem is MainPage viewModel)
  {
          viewModel.IsVisible = true;
  }
           //    ChallengeList.SelectedItem = null;
} 

XAML:

<ListView x:Name="ChallengeList" SeparatorColor="#3d122c" HasUnevenRows="True"
            ItemSelected="ChallengeList_ItemSelected"  RelativeLayout.YConstraint="{ConstraintExpression ElementName=Lab, Constant=0,Factor=1,Property=Height,Type=RelativeToView}"
      RelativeLayout.HeightConstraint="{ConstraintExpression Property=Height,Factor=0.8,Type=RelativeToParent}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal"  BackgroundColor="#40FFFFFF" Padding="10">
                            <StackLayout HorizontalOptions="CenterAndExpand">
                                <Label Text="{Binding Title}" TextColor="#ff3f50" FontSize="17" FontAttributes="Bold" HorizontalOptions="Center"/>
                                <StackLayout HorizontalOptions="CenterAndExpand" IsVisible="{Binding IsVisible}" x:Name="More" Padding="5">
                                    <Label Text="sdfghjkhgfdsfghjkljhgfdsadfghjkljhgfdsaSDFGHJKJHGFDSAsdfghjkhgfds" TextColor="#ff3f50" FontSize="17" FontAttributes="Bold" HorizontalOptions="Center"
                                           LineBreakMode="WordWrap"/>
                                </StackLayout>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
</ListView>

2 个答案:

答案 0 :(得分:1)

我不太确定您使用Set函数做了什么,但我通常会在我的viewmodel中设置属性,如下所示:

var val1 = (string)trans?.Descendants("Set")?.Elements("szSerialNmbr")?.FirstOrDefault()?.Value;

答案 1 :(得分:0)

    private bool _isVisible = false;

    public bool IsVisible
    {
        get
        {
            return _isVisible
        }
        set
        {
            Set(() => IsVisible, ref _isVisible, value);
        }
    }

这对我有用!