【发布时间】:2020-04-27 00:54:35
【问题描述】:
我有一个课程PricingData 和PricingSchedule。其中PricingSchedule 是PricingData 类中的List。我想将此类的数据绑定到 UWP 控件。
示例代码可在此处下载:https://github.com/jigneshdesai/SampleOfBindingIssue1.git
代码的外观: 我有一个承载 ListView 控件的起始页(主页),Listview 中包含 PricingUserControl。 PricingUserControl 看起来像这样
<TextBlock x:Name="lblPriceHeader" Text="{Binding PricingTitle}" Margin="0,0,50,0" />
<ComboBox x:Name="cbPriceValueList" ItemsSource="{x:Bind dpl}" DisplayMemberPath="PriceValue" SelectedValuePath="PriceValue" SelectedValue="{Binding DisplayPricing}" />
<ListView x:Name="lbPriceChangeSchedule" ItemsSource="{Binding PricingScheduleList}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="cbSchedulePriceValueList" ItemsSource="{x:Bind dpl}" DisplayMemberPath="PriceValue" SelectedValuePath="PriceValue" />
<TextBlock Text="{Binding SchedulePricingTimeZone }" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我想要实现的目标:组合框应填充值列表(例如 1USD、2USD、3USD 等)。然后,当您提供数据库中的记录列表时,列表框将重复 PricingUserControl,其中的组合框应根据记录设置其值属性 (SelectedValue)。
问题: ComboBox x:Name="cbPriceValueList" 使用 x:bind dpl,其中 dpl 是 PricingUserControl 的局部变量。它正确地填充列表。问题是 ComboBox x:Name="cbSchedulePriceValueList" 它也有 x:bind dpl 但在编译期间它显示错误 "Invalid binding path 'dpl' : Property 'dpl' not在类型 'DataTemplate' 上找到。”
我想知道为什么 x:bind dpl 在这一点上不起作用。 ?
【问题讨论】: