0
我想綁定的SelectedItem,這是另一個列表框裏面裏面,但我從輸出這個綁定錯誤:綁定的SelectedItem另一個列表框
System.Windows.Data Error: BindingExpression path error: 'Time' property not found on '[23, System.Collections.Generic.List`1[MarsrutaiAPI.ArrivalTime]]' 'System.Collections.Generic.KeyValuePair`2[System.Int32,System.Collections.Generic.List`1[MarsrutaiAPI.ArrivalTime]]' (HashCode=1268928309). BindingExpression: Path='Time' DataItem='[23, System.Collections.Generic.List`1[MarsrutaiAPI.ArrivalTime]]' (HashCode=1268928309); target element is 'System.Windows.Controls.ListBox' (Name='innerList'); target property is 'SelectedItem' (type 'System.Object')..
嵌套的列表框被宣佈爲:
<ListBox ItemsSource="{Binding TimeTable}" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityNegativeConverter}}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Key}" Style="{StaticResource NormalText}" FontSize="42" Margin="0,0,10,0" HorizontalAlignment="Center" />
<ListBox Grid.Column="1" Name="innerList" ItemsSource="{Binding Value}" SelectedItem="{Binding Time,Mode=TwoWay}" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBoxItem Margin="0,0,5,5"/>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource tekstas}" BorderThickness="1" CornerRadius="5" Margin="5" Background="{Binding IsAccessible,Converter={StaticResource IsAccessibleToColor}}">
<TextBlock Style="{StaticResource NormalText}" Text="{Binding ExpectedTime, StringFormat=\{0:mm\}}" Margin="10" HorizontalAlignment="Center"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border Grid.Row="1" Grid.ColumnSpan="2" Margin="10"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
時間表屬性:public Dictionary<int, List<ArrivalTime>> TimeTable
時間屬性的ArrivalTime
整個綁定工作,完美,除了的SelectedItem,即使我有必要的財產在我的VM
private ArrivalTime _time;
public ArrivalTime Time
{
get { return _time; }
set
{
_time = value;
RaisePropertyChanged("Time");
}
}
感謝您的幫助:)
可悲的是Windows phone的,所以我認爲AncestorType不支持 – Domas
,也<列表框Grid.Column = 「1」 NAME = 「innerList」 的ItemsSource = 「{綁定值}」 的SelectedItem =」 {綁定DataContext.Time,ElementName = gridFoo}「ScrollViewer.VerticalScrollBarVisibility =」已禁用「> –
謝謝!那一個工作,將永遠不會弄明白我自己:) – Domas