Wpf 是否将列表的SelectedIndex属性绑定到Windows Phone 8中相同/另一个项目中不同类的属性?

Wpf 是否将列表的SelectedIndex属性绑定到Windows Phone 8中相同/另一个项目中不同类的属性?,wpf,xaml,data-binding,mvvm,windows-phone-8,Wpf,Xaml,Data Binding,Mvvm,Windows Phone 8,当我将列表的SelectedIndex绑定到属性时,有些事情我无法理解。只有当属性是这个XAML页面的代码隐藏的一部分时,它才起作用 例如:如果有test.xaml、test.xaml.cs和AppSettings.cs,则只有当SelectedIndex属性绑定到test.xaml.cs中的属性时,绑定才能正常工作 经过一些试验,我发现如果我设置ItemSource并在代码中编写所有绑定内容,即使属性在binder.cs中也能工作 我认为与ItemSource的顺序相关,然后选择EditIte

当我将列表的SelectedIndex绑定到属性时,有些事情我无法理解。只有当属性是这个XAML页面的代码隐藏的一部分时,它才起作用

例如:如果有test.xaml、test.xaml.cs和AppSettings.cs,则只有当SelectedIndex属性绑定到test.xaml.cs中的属性时,绑定才能正常工作

经过一些试验,我发现如果我设置ItemSource并在代码中编写所有绑定内容,即使属性在binder.cs中也能工作

我认为与ItemSource的顺序相关,然后选择EditItem

财产的代码

      private Currency sTileCurrency;

    public Currency STileCurrency
    {
        get
        {
            return GetValueorDefault<Currency>("STileCurrency", null);

        }

        set
        {
            sTileCurrency = value;
            if (AddOrUpdateValue("STileCurrency", value))
            {
                settings.Save();
            }
        }
    }

当我尝试在XAML中设置ItemSource并在Codebehind中绑定时,它也不起作用

appSettings是什么,SCurrencyList是在哪里定义的?我们在这里使用的是viewmodel吗?我现在更正了变量的名称,appSettings是appSettings.cs类的一个实例,在包含此列表的网格的参考资料部分中定义。CorrencyList在另一个名为Binder的类中定义,instance是它的一个静态实例。是的,我正在尝试使用viewmodel(用于主页的Binder)和(AppSettings用于设置页面)但这是我第一次使用它。
    <ListBox  Name="sCurrencyLB" Margin="10,0,0,0" Width="Auto" Height="180" ItemsSource="{Binding SCurrencyList}" SelectedItem="{Binding STileCurrency, Source={StaticResource appSettings}, Mode=TwoWay}"  >                                     
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                                        <TextBlock Name="scountryNametb" Width="50" Text="{Binding code}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                                        <Image Source="{Binding imgUrl}" Height="50" Width="50" HorizontalAlignment="Left" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
        sCurrencyLB.ItemsSource = Binder.Instance.SCurrencyList;
        Binding binding = new Binding();
        binding.Mode = BindingMode.TwoWay;
        binding.Source = settings;
        binding.Path = new PropertyPath("STileCurrency");
        sCurrencyLB.SetBinding(ListBox.SelectedItemProperty, binding);