私のページには、以下に示すように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 が必要です。プロジェクトを実行します。最初または最後のラジオ ボタンを選択します。次に、日付を選択します。以前に選択したラジオ ボタンがオフになっていることを確認します。