且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将视图模型绑定到视图

更新时间:2022-06-04 02:45:09

在您的XAML中,绑定到路径名称地址您是否在 ItemViewModel 中定义了这2个属性?

In your XAML you bind to paths Name and Address do you have these 2 properties defined in your ItemViewModel?

正确阅读代码后更新:

您没有更新列表框项目的数据表。这是你需要做的:

You are not updating the datatemplate of the Items of the Listbox. This is what you need to do:

<ListBox x:Name="FavoritesListBox" ItemsSource="{Binding FavoriteItems}" SelectionChanged="FavoritesListBox_SelectionChanged">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Margin="12,0,12,0">
                <Image x:Name="favicon" Source="{Binding Favicon}" Width="50" Height="50"/>
                <StackPanel>
                    <TextBlock x:Name="favoritesName" Text="{Binding Name}" FontSize="{StaticResource PhoneFontSizeExtraLarge}"/>
                    <TextBlock x:Name="favoritesAddress" Text="{Binding Address}" Margin="12,0,0,0"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>