我在Telerik RadJumpList的ItemTemplate中使用Checkbox控件。 ItemTemplate的定义如下:
<DataTemplate x:Key="ItemTemplate">
<StackPanel Orientation="Horizontal"
Margin="4">
<Image Source="/Assets/Weather.png"
Width="64"
Height="64"
Margin="0,4,12,4" Stretch="Fill" />
<CheckBox x:Name="checkBox"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Checked="checkBox_CheckedChanged"
Unchecked="checkBox_CheckedChanged" />
<TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyLight}"
Text="{Binding Name}"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
JumpList的定义如下:
<telerikDataControls:RadJumpList Grid.Row="1"
x:Name="FavoriteJumpList"
ItemTemplate="{StaticResource ItemTemplate}"
GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}"
StickyHeaderTemplate="{StaticResource StickyHeaderTemplate}"
GroupPickerItemsPanel="{StaticResource ItemsPanelTemplate}"
ItemTap="FavoriteJumpList_ItemTap">
<telerikDataControls:RadJumpList.GroupPickerItemTemplateSelector>
<local:PhoneBookTemplateSelector x:Name="TemplateSelector"
EmptyItemTemplate="{StaticResource EmptyItemTemplate}"
LinkedItemTemplate="{StaticResource LinkedItemTemplate}" />
</telerikDataControls:RadJumpList.GroupPickerItemTemplateSelector>
</telerikDataControls:RadJumpList>
事件处理程序的定义如下:
private void checkBox_CheckedChanged( object sender, RoutedEventArgs e )
{
var count = _app.AppData.Favorites.FavoritePoints.Count( favorite => favorite.IsChecked );
WriteLine( "Count {0}", count );
}
在页面的c#中,JumpList初始化如下:
FavoriteJumpList.IsAsyncBalanceEnabled = true;
FavoriteJumpList.IsStickyHeaderEnabled = true;
FavoriteJumpList.GroupCheckMode = GroupCheckMode.None;
FavoriteJumpList.ItemCheckedStateChanged += FavoriteJumpList_ItemCheckedStateChanged;
// add custom group picker items, including all alphabetic characters
var groupPickerItems = new List<string>( 32 );
foreach ( var c in Alphabet )
{
groupPickerItems.Add( new string( c, 1 ) );
}
FavoriteJumpList.GroupPickerItemsSource = groupPickerItems;
// add the group and sort descriptors
var groupByFirstName = new GenericGroupDescriptor<FavoriteLocation, string>( favoriteLocation => favoriteLocation.Name.Substring( 0, 1 ).ToLower() );
FavoriteJumpList.GroupDescriptors.Add( groupByFirstName );
var sort = new GenericSortDescriptor<FavoriteLocation, string>( favoriteLocation => favoriteLocation.Name );
FavoriteJumpList.SortDescriptors.Add( sort );
// assign data source
LoadFavorites();
FavoriteJumpList.ItemsSource = _app.AppData.Favorites.FavoritePoints;
我放了两个断点。一行在checkBox_CheckedChanged就行了:
WriteLine( "Count {0}", count );
和RaisePropertyChanged一行:
private bool _isChecked;
[DataMember]
public bool IsChecked
{
get
{
return _isChecked;
}
set
{
_isChecked = value;
RaisePropertyChanged( "IsChecked" );
}
}
两个断点都被触发。但是,我得到了断点
checkBox_CheckedChanged()
被触发之前
RaisePropertyChanged( "IsChecked" );
被触发,这是不可接受的(也是意外的)。
中的count变量checkBox_CheckedChanged()
用于启用/禁用工具栏按钮,计数滞后并显示错误值。
任何想法为什么在这里触发错误的事件顺序(或延迟),以及如何正确处理它?</ p>
THX
答案 0 :(得分:0)
MJW的回答是正确的。但是为了解决我的问题,我修改了代码,以便在触发CheckBox单击事件时完成计数计算。
它适用于我的私人案例,但我不确定在数据已经更新(即绑定已经完成)之后是否触发click事件的规则。
THX。