0
我正在使用wp8应用程序。 其中一个屏幕应该有支点。两个数据透视表项应该包含LongListSelectors(同样的ItemTemplate,不同的ItemSource,但是对于这个例子相同的ItemSource)。LongListSelector不绑定到数据源
<phone:PivotItem x:Name="piSite" Header="{Binding Path=LocalizedResources.FILTER_SITE, Source={StaticResource LocalizedStrings}}" Style="{StaticResource piStyleMaster}" FontFamily="{StaticResource PhoneFontFamilyNormal}">
<phone:LongListSelector x:Name="lbSites" ItemTemplate="{StaticResource dtFilter}"/>
</phone:PivotItem>
<phone:PivotItem x:Name="piTags" Header="{Binding Path=LocalizedResources.FILTER_TAG, Source={StaticResource LocalizedStrings}}" Style="{StaticResource piStyleMaster}" FontFamily="{StaticResource PhoneFontFamilyNormal}">
<phone:LongListSelector x:Name="lbTags" ItemTemplate="{StaticResource dtFilter}"/>
</phone:PivotItem>
这是我这些名单的DataTemplate:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="dtFilter">
<Grid x:Name="grFilter">
<CheckBox x:Name="cbFilter" Content="{Binding filterName}" IsChecked="{Binding isChecked}" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="{StaticResource ForegroundThemeBrush}" Foreground="{StaticResource ForegroundThemeBrush}"/>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
,我使用的数据模型是:
public class CheckableFilter
{
public string filterName;
public bool isChecked;
}
,这里是我如何设置的ItemSource:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var testItemSource = new ObservableCollection<CheckableFilter>
{
new CheckableFilter {filterName = "first name", isChecked = false},
new CheckableFilter {filterName = "second name", isChecked = true},
new CheckableFilter {filterName = "third name", isChecked = false},
new CheckableFilter {filterName = "fourth name", isChecked = true},
new CheckableFilter {filterName = "fifth name", isChecked = false}
};
lbSites.ItemsSource = testItemSource;
lbTags.ItemsSource = testItemSource;
base.OnNavigatedTo(e);
}
顺便说一句,前景a边框颜色的CheckBoxes是蓝色的,背景是白色的。
我得到了正确数量的元素,就像你在屏幕截图上看到的那样,它显示了正确的复选框数量。问题是没有filterName(CheckBox的内容)。
如果我排除的复选框内容绑定:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="dtFilter">
<Grid x:Name="grFilter" DataContext="{Binding}">
<CheckBox x:Name="cbFilter" Content="Test Value" IsChecked="{Binding isChecked}" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="{StaticResource ForegroundThemeBrush}" Foreground="{StaticResource ForegroundThemeBrush}"/>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
我得到以下结果:
我在做什么错了,所以我的结合是不工作的复选框内容在LLS dataTemplate中?
谢谢你的回答和建议。祝一切顺利。 – Slavisa 2015-03-02 12:18:26