1
请看看这个:数据绑定在XAML的SelectedItem
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
DataContext="{StaticResource vm}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="194*"/>
<ColumnDefinition Width="489*"/>
</Grid.ColumnDefinitions>
<ListView HorizontalAlignment="Left"
ItemsSource="{Binding Path=Places}"
SelectedItem="{Binding Path=SelectedPlace, Mode=TwoWay}" Margin="0,96,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Title}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackPanel Grid.Column="0" HorizontalAlignment="Left">
<TextBlock
VerticalAlignment="Top"
Text="{Binding SelectedPlace.Title}" Margin="0,64,0,0"/>
</StackPanel>
</Grid>
我在路过的地方名单,其做工精细和列表被显示在视图中。问题是selectedItem
。智能感知在这里找到属性
Text="{Binding SelectedPlace.Title}"
但它不显示在视图中。 当我把一个断点在我的视图模型,我可以看到,该值的变化:
public class MainViewModel : ViewModelBase
{
public ObservableCollection<Place> Places { get; set; }
public Place _selectedPlace { get; set; }
public Place SelectedPlace
{
get { return _selectedPlace; }
set { _selectedPlace = value; }
}
public MainViewModel()
{
Places = new ObservableCollection<Place>()
{
new Place() {Title = "London", Description = "London is a nice..."},
new Place() {Title = "Dublin", Description = "Dublin is a ...."}
};
}
}
有谁知道我缺少什么?谢谢
完美!谢谢! – Wranglerino 2014-11-22 21:33:01