Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取listview子项并从代码隐藏中动态删除一段代码_C#_Xamarin_Xamarin.forms_Syncfusion - Fatal编程技术网

C# 如何获取listview子项并从代码隐藏中动态删除一段代码

C# 如何获取listview子项并从代码隐藏中动态删除一段代码,c#,xamarin,xamarin.forms,syncfusion,C#,Xamarin,Xamarin.forms,Syncfusion,我正在努力解决Xamarin框架在“显示/隐藏”内容时占用额外空间的问题。我看过几篇相关文章,并实现了内容模板,但都没有解决这个问题 基本上,我有一个包含SyncfusionListView的详细视图。使用这样的ListView我呈现的卡片应该是动态的,有些包含图表,有些不包含图表,卡片包含基于类别的不同信息 这是我的DetailCard实现: public class DetailCard : BaseCard { public bool ChartDataVi

我正在努力解决Xamarin框架在“显示/隐藏”内容时占用额外空间的问题。我看过几篇相关文章,并实现了内容模板,但都没有解决这个问题

基本上,我有一个包含Syncfusion
ListView
的详细视图。使用这样的
ListView
我呈现的卡片应该是动态的,有些包含图表,有些不包含图表,卡片包含基于类别的不同信息

这是我的
DetailCard
实现:

    public class DetailCard : BaseCard
    {
        public bool ChartDataVisible { get; set; }
        public string detailsList;

        public DetailCard()
        {
            ChartDataVisible = false;
        }
    }

    public class BaseCard : INotifyPropertyChanged
    {
        #region Field

        private IReadOnlyCollection<ChartModel> chartData;

        #endregion

        #region Events

        /// <summary>
        /// The declaration of the property changed event.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Property

        /// <summary>
        /// Gets or sets the property that has been displays the Category.
        /// </summary>
        public string Category { get; set; }

        /// <summary>
        /// Gets or sets the property that has been displays the Category value.
        /// </summary>
        public string CategoryValue { get; set; }

        /// <summary>
        /// Gets or sets the property that has been displays the Category percentage.
        /// </summary>
        public string CategoryPercentage { get; set; }

        /// <summary>
        /// Gets or sets the property that has been bound with SfChart Control, which displays the health care data visualization.
        /// </summary>
        public IReadOnlyCollection<ChartModel> ChartData
        {
            get
            {
                return this.chartData;
            }

            set
            {
                if (this.chartData == value)
                {
                    return;
                }

                this.chartData = value;
                this.OnPropertyChanged("ChartData");
            }
        }

        /// <summary>
        /// Gets or sets the property that has been displays the background gradient start.
        /// </summary>
        public string BackgroundGradientStart { get; set; }

        /// <summary>
        /// Gets or sets the property that has been displays the background gradient end.
        /// </summary>
        public string BackgroundGradientEnd { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// The PropertyChanged event occurs when changing the value of property.
        /// </summary>
        /// <param name="property">Property name</param>
        protected void OnPropertyChanged(string property)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
        }

        #endregion
    }
公共类详细信息卡:基本卡
{
公共布尔ChartDataVisible{get;set;}
公共字符串详细信息列表;
公共信息卡()
{
ChartDataVisible=false;
}
}
公共类基卡:INotifyPropertyChanged
{
#区域场
私人IReadOnlyCollection图表数据;
#端区
#地区活动
/// 
///属性的声明已更改事件。
/// 
公共事件属性更改事件处理程序属性更改;
#端区
#区域属性
/// 
///获取或设置已显示类别的属性。
/// 
公共字符串类别{get;set;}
/// 
///获取或设置已显示类别值的属性。
/// 
公共字符串CategoryValue{get;set;}
/// 
///获取或设置已显示类别百分比的属性。
/// 
公共字符串CategoryPercentage{get;set;}
/// 
///获取或设置已与SfChart控件绑定的属性,该控件显示医疗保健数据可视化。
/// 
公共IReadOnlyCollection图表数据
{
得到
{
返回此.chartData;
}
设置
{
if(this.chartData==值)
{
返回;
}
this.chartData=值;
本.OnPropertyChanged(“图表数据”);
}
}
/// 
///获取或设置显示背景渐变开始的属性。
/// 
公共字符串BackgroundGradientStart{get;set;}
/// 
///获取或设置显示背景渐变结束的属性。
/// 
公共字符串BackgroundGradientEnd{get;set;}
#端区
#区域方法
/// 
///更改属性值时发生PropertyChanged事件。
/// 
///属性名
受保护的void OnPropertyChanged(字符串属性)
{
this.PropertyChanged?.Invoke(this,newpropertyChangedEventArgs(property));
}
#端区
}
这是我的图表视图控件模板(请注意,通过我的模型中的布尔绑定,这将是可见的或不可见的):


以下是详细信息内容页面的列表视图:


       <listView:SfListView
            x:Name="listViewCards"
            AutoFitMode="Height"
            IsScrollingEnabled="False"
            ItemSize="74"
            ItemsSource="{Binding CardItems}"
            SelectionMode="None"
            TapCommand="{Binding ItemTappedCommand}">
            <listView:SfListView.ItemTemplate>
                <DataTemplate>
                    <svg:CustomShadowFrame
                        x:Name="shadowFrame"
                        Margin="16,8"
                        Padding="0"
                        BackgroundColor="{DynamicResource GrayShadowColor}"
                        BorderWidth="0"
                        CornerRadius="4"
                        HasShadow="True"
                        HorizontalOptions="CenterAndExpand"
                        Radius="4"
                        WidthRequest="{OnIdiom Phone=343,
                                               Default=736}">

                        <Grid
                            Padding="16"
                            RowDefinitions="Auto, *"
                            RowSpacing="5">

                            <!--  Category  -->
                            <Label
                                HeightRequest="24"
                                HorizontalOptions="Start"
                                Style="{StaticResource TitleLabelStyle}"
                                Text="{Binding CategoryValue}" />

                            <!--  Category Value  -->
                            <Label
                                Grid.Row="1"
                                FontSize="15"
                                HeightRequest="{Binding Category}"
                                HorizontalOptions="FillAndExpand"
                                HorizontalTextAlignment="Start"
                                Style="{StaticResource DescriptionLabelStyle}"
                                Text="{Binding Category}" />

                            <ContentView 
                                x:Name="chartView"
                                Grid.Row="2"
                                ControlTemplate="{StaticResource ChartView}" >
                            </ContentView>
                        </Grid>

                    </svg:CustomShadowFrame>
                </DataTemplate>
            </listView:SfListView.ItemTemplate>


这里是结果

我仍然没有讨论如何解决这个问题,但现在我正在考虑从每个帧中删除内容视图,如果我的图表标志为false,如何从代码隐藏中实现这一点?我无法从列表视图中获得如下帧列表:

        protected override void OnAppearing()
        {
            base.OnAppearing();
            var listView = listViewCards as Syncfusion.ListView.XForms.SfListView;
            var itemSource = listView.ItemsSource as ObservableCollection<DetailCard>;
            var itemTemplate = listView.ItemTemplate;
    
            //I need a mechanism here to loop into all Frames from list view and remove the content view code

        }

<Grid
    Padding="16"
    RowDefinitions="Auto, *, Auto"
    RowSpacing="5">
<ContentView 
     x:Name="chartView"
     Grid.Row="2"
     IsVisible="{Binding IsChartDataAvailable}"
     ControlTemplate="{StaticResource ChartView}"/>
protected override void OnAppearing()
{
base.OnAppearing();
var listView=listViewCards作为Syncfusion.listView.XForms.SfListView;
var itemSource=listView.itemSource作为ObservableCollection;
var itemTemplate=listView.itemTemplate;
//这里我需要一种机制来循环列表视图中的所有帧,并删除内容视图代码
}

您是否尝试将
SfListView.AutoFitMode
设置为
DynamicHeight
<如果单元格中的控件更改大小或隐藏在视图中,则代码>动态灯光将动态更改单元格的高度。它可能会根据图表的初始高度调整单元格大小,然后一旦绑定生效,高度会发生变化,但单元格不会更新

您可能还希望将包含图形的网格列上的行高设置为“自动”,以便行自动折叠

Syncfusion文档:


我最终将行定义添加到每个帧行并绑定行大小,这可能不是最好的方法,但对我来说很有效:

    public class DetailCard : BaseCard
    {
        public bool ChartDataVisible { get; set; }
        public GridLength RowSize { get; set; }
        public string DetailsList { get; set; }

        public DetailCard()
        {
            ChartDataVisible = false;
            RowSize = new GridLength(0);
        }
    }

你好,费尔南多,
感谢您使用syncfusion产品。
#项目下方的空白间距。
我们已经检查了我们端报告的查询。我们想通知您,视图中的空白是contentview。我们建议您将IsVisible属性绑定到ContentView,而不是StackLayout,以克服报告的情况。请参考以下代码段。
代码段:
#在运行时删除代码。
我们已经检查了我方报告的查询。无法直接从ItemTemplate获取元素。但是,您可以使用不同的布局处理ItemTemplate,就像您的图表标志为false一样。您可以在SfListView中的DataTemplateSelector的帮助下使用另一个模板。
您也可以参考以下UG文档链接。
UG链接:https://help.syncfusion.com/xamarin/listview/v
Hi Fernando, 
 
Thank you for using syncfusion products. 
 
# Empty spacing below the items. 
We have checked the reported query from our end. We would like to inform you that the empty space in the view is a contentview. We suggest to you to bind the IsVisible property to the ContentView instead of StackLayout to overcome the reported scenario. Please refer to the following code snippet. 
 
Code snippet: 
<ContentView  
            x:Name="chartView" 
            IsVisible = "{Binding ChartDataVisible}" 
            Grid.Row="2" 
            ControlTemplate="{StaticResource ChartView}" > 
</ContentView> 
 
# Remove the code at a runtime. 
We have checked the reported query from our side. You cannot get the elements from the ItemTemplate directly. However you can handle the ItemTemplate with different layout like you’re your chart flag is false you can use another template with the help of DataTemplateSelector in a SfListView. 

You can also refer to the following UG Documentation link for your reference. 
UG Link:https://help.syncfusion.com/xamarin/listview/viewappearance#data-template-selector 
  
Or you can stick with the above solution with IsVisible property. Based on chart flag you can architect your UI. Please let us know if you would require further assistance.
 
Regards, 
SaiGanesh Sakthivel 
<Grid
    Padding="16"
    RowDefinitions="Auto, *, Auto"
    RowSpacing="5">
<ContentView 
     x:Name="chartView"
     Grid.Row="2"
     IsVisible="{Binding IsChartDataAvailable}"
     ControlTemplate="{StaticResource ChartView}"/>