Xaml 如何使用在xamarin.forms中选择的选项设置母版详细信息页?

Xaml 如何使用在xamarin.forms中选择的选项设置母版详细信息页?,xaml,xamarin,xamarin.forms,master-pages,Xaml,Xamarin,Xamarin.forms,Master Pages,我正在使用Master details页面创建应用程序。在这方面,我遗漏了一件事,那就是当我打开一个应用程序时,这里没有选择第一项。 我尝试使用不同的解决方案,如制作“自定义视图单元”,并制作渲染器来解决该问题,但也会出现同样的问题 我还提到了下面的图片 有什么解决方案吗?这有点复杂,完全可以在Forms project中完成,而无需自定义渲染器 我列出了实现你想要的目标的步骤 指定模型属性以指示选择了哪一个,并实现“INotifyPropertyChanged” public class M

我正在使用Master details页面创建应用程序。在这方面,我遗漏了一件事,那就是当我打开一个应用程序时,这里没有选择第一项。 我尝试使用不同的解决方案,如制作“自定义视图单元”,并制作渲染器来解决该问题,但也会出现同样的问题

我还提到了下面的图片


有什么解决方案吗?

这有点复杂,完全可以在Forms project中完成,而无需自定义渲染器

我列出了实现你想要的目标的步骤

  • 指定模型属性以指示选择了哪一个,并实现“INotifyPropertyChanged”

    public class MasterPageItem  : INotifyPropertyChanged
    {
        private bool isSelected;
        public bool IsSelected {
            get {
                return isSelected;
            }
            set {
                if (value != this.isSelected)
                {
                    this.isSelected = value;
                    NotifyPropertyChanged();
                }
            } 
        }
    }
    
  • 在ViewCell中绑定父视图的背景色,并在转换器中将布尔值转换为颜色

                <ViewCell>
                    <Grid Padding="5,10" BackgroundColor="{Binding IsSelected , Converter={StaticResource BooltoColor}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" />
                    </Grid>
                </ViewCell>
    
    public class BooltoColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Color color ;
    
            if(((bool)value) == true)
            {
                color = Color.Gray;
            }
            else
            {
                color = Color.Transparent;
            }
    
            return color;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return true;
        }
    }
    
  • 检查我的测试图像和下面的示例链接


    你能举个例子说明你到底在寻找什么吗?@AnubhavRanjan谢谢你的回答。我补充了详细的问题,请调查,并做必要的。也许会有帮助。
    private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        foreach (MasterPageItem i in list)
        {
            i.IsSelected = false;
        }
    
        MasterPageItem item = e.Item as MasterPageItem;
        if (item != null)
        {
            item.IsSelected = true;
            list.RemoveAt(e.ItemIndex);
            list.Insert(e.ItemIndex, item);
        }
    }