【发布时间】:2011-07-03 10:35:47
【问题描述】:
我有两个具有相同数据绑定的列表选择器(来自 XML),当第一个列表选择器更改选择时,它应该过滤第二个列表选择器的数据并隐藏在第一个列表选择器中选择的项目,与第二个列表选择器相同。
2 列表选择器 XAML...
<my:ListPicker HorizontalAlignment="Left"
x:Name="listPicker1" Width="265" BorderBrush="{x:Null}" FontFamily="Segoe UI" FontSize="18.667" Background="{StaticResource PhoneTextBoxBrush}" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="147,0,0,0" Grid.Row="1" Foreground="#FF1BA1E2" Height="35" SelectionChanged="listPicker1_SelectionChanged" >
<my:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Width="360" Height="34">
<TextBlock x:Name="item" Text="{Binding ChannelName, Mode=TwoWay}" FontSize="18.667" Margin="12, 0, 2, 2" />
</StackPanel>
</DataTemplate>
</my:ListPicker.ItemTemplate>
</my:ListPicker>
<TextBlock TextWrapping="Wrap" FontFamily="Segoe UI" FontSize="16" Margin="52,5,0,5" Grid.Row="3" HorizontalAlignment="Left" Width="91" Text="Channel 2 "/>
<my:ListPicker HorizontalAlignment="Left"
x:Name="listPicker2" Width="265" BorderBrush="{x:Null}" FontFamily="Segoe UI" FontSize="18.667" Background="{StaticResource PhoneTextBoxBrush}" Foreground="#FF1BA1E2" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="147,0,0,0" Grid.Row="3" SelectionChanged="listPicker2_SelectionChanged" >
<my:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Width="360" Height="34">
<TextBlock x:Name="item" Text="{Binding ChannelName, Mode=TwoWay}" FontSize="18.667" Margin="12, 0, 2, 2" />
</StackPanel>
</DataTemplate>
</my:ListPicker.ItemTemplate>
</my:ListPicker>
使用 XML 代码进行数据绑定
public Customize()
{
InitializeComponent();
XDocument loadedData = XDocument.Load("newsChannels.xml");
var channels = from query in loadedData.Descendants("channel")
select new Channels
{
ChannelName = (string)query.Element("channelname"),
};
listPicker1.ItemsSource = channels;
listPicker2.ItemsSource = channels;
}
public class Channels
{
string channelname;
public string ChannelName
{
get { return channelname; }
set { channelname = value; }
}
}
【问题讨论】:
标签: windows windows-phone-7 silverlight-4.0 silverlight-toolkit