0

私のページには、以下に示すようにLongListSelector&があります。DatePicker

<phone:LongListSelector ItemsSource="{Binding Categories, Mode=TwoWay}"
                        Name="llsCategories"
                        ItemTemplate="{StaticResource AllCategories}"/>

<toolkit:DatePicker Name="dpDate" Value="{Binding LastModifiedOn,Mode=TwoWay}"/>

の DataTemplate を定義した方法は次のとおりですLongListSelector。お知らせ、GroupNameプロパティ

    <DataTemplate x:Key="AllCategories">
        <StackPanel Orientation="Vertical">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions >
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <RadioButton Content="{Binding CategoryName, Mode=TwoWay}" 
                             IsChecked="{Binding IsCategorySelected, Mode=TwoWay}"
                             GroupName="categoryList"/>
            </Grid>
        </StackPanel>
    </DataTemplate>

LongListSelector のデータソースCategoriesは、IList<Category>既に実装されている Viewmodel に存在しますINotifyPropertyChanged

これが私がデータバインドする方法です。

ページのコンストラクター:

this.DataContext = App.ViewModel

App.xaml 内

private static MainViewModel viewModel = null;
 public static MainViewModel ViewModel
        {
            get
            {
                // Delay creation of the view model until necessary
                if (viewModel == null)
                    viewModel = new MainViewModel();

                return viewModel;
            }
        }

問題: LongListSelector に表示されているカテゴリ (ラジオ ボタン) の 1 つを選択し、datetime の選択が完了すると、以前にチェックされていたラジオ ボタンのチェックが外れます。なんで ?

編集:サンプル コード は次のとおりです。VS 2012 が必要です。プロジェクトを実行します。最初または最後のラジオ ボタンを選択します。次に、日付を選択します。以前に選択したラジオ ボタンがオフになっていることを確認します。

4

1 に答える 1

0

いくつかの問題。あなたの主なバインディングの問題は、代わりにIsCategorySelectedプロパティが on であるためです( notの選択されたプロパティをバインドしているため)。MainViewModelCategoryCategoryMainViewModel

さらに、次のように、コンストラクターで一度リストを初期化するのではなく、常にカテゴリ リストを再作成するのでMainViewModel.Categoriesはなく、次のようにします。

public MainViewModel()
        {
            _categories = new List<Category>();
            Category c1 = new Category { CategoryName = "Hi" };
            Category c2 = new Category { CategoryName = "Hello" };
            Category c3 = new Category { CategoryName = "Howdy" };
            _categories = new List<Category>();
            _categories.Add(c1);
            _categories.Add(c2);
            _categories.Add(c3);
        }

それが役立つことを願っています!

于 2013-05-28T18:48:07.143 に答える