在我的wp8应用程序中,我有列表框,在我的列表框中,我有3个按钮和一个文本。按钮从字符串列表中获取标签,我还想将我的Texblock与另一个字符串列表绑定。
但是如何将textblock与其他来源绑定
这是我的列表框
<ListBox Name="URLListBox" Grid.Column="1">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent" Margin="0,0,0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="75"></ColumnDefinition>
<ColumnDefinition Width="75"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="surename" Grid.Column="0" Text="{Binding}" Grid.Column="0" TextWrapping="Wrap" HorizontalAlignment="Left"/>
<Button Tag="{Binding}" Grid.Column="1" Content="download" Height="72" Name="button1" Width="80" FontSize="15" Click="addButton_Click"/>
<Button Tag="{Binding}" Grid.Column="2" Content="play" Height="72" Name="play_Click" Width="80" FontSize="15" Click="play_Click"/>
<Button Tag="{Binding}" Grid.Column="3" Content="pause" Height="72" Name="pause_Click" Width="80" FontSize="15" Click="pause_Click"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
另一个问题是当你向下滚动时,但当你离开屏幕时,它会上升到原来的位置
答案 0 :(得分:0)
使用Concat
组合您的列表。它将创建一个IEnumerable
列表
在 XAML 中,我正在创建列表框;
<ListBox x:Name="listbox"/>
在代码隐藏中, C#
public MainPage()
{
InitializeComponent();
var ListOne = new List<string> { "A", "B", "C" };
var ListTwo = new List<string> { "D", "E", "F" };
var Combined = ListOne.Concat(ListTwo);
listbox.ItemsSource = Combined;
}
答案 1 :(得分:0)
试试这个:
XAML:
<ListBox Name="URLListBox" Grid.Column="1">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent" Margin="0,0,0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="75"></ColumnDefinition>
<ColumnDefinition Width="75"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="surename" Grid.Column="0" Text="{Binding text}" TextWrapping="Wrap" HorizontalAlignment="Left"/>
<Button Tag="{Binding b1Tag}" Grid.Column="1" Content="download" Height="72" Name="button1" Width="80" FontSize="15" Click="addButton_Click"/>
<Button Tag="{Binding b1Tag}" Grid.Column="2" Content="play" Height="72" Name="play_Click" Width="80" FontSize="15" Click="play_Click"/>
<Button Tag="{Binding b1Tag}" Grid.Column="3" Content="pause" Height="72" Name="pause_Click" Width="80" FontSize="15" Click="pause_Click"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
CS:
public void LoadData()
{
List<string> TextData = new List<string> { "Text1", "Text2", "Text3", "Text4" };
List<string> BtnData = new List<string> { "B1Tag", "B2Tag", "B3Tag", "B4Tag" };
ObservableCollection<URLListBoxCalss> obj = new ObservableCollection<URLListBoxCalss>();
for (int i = 0; i < 4; i++)
{
obj.Add(new URLListBoxCalss(TextData[i], BtnData[i], BtnData[i], BtnData[i]));
}
URLListBox.ItemsSource = obj;
}
public class URLListBoxCalss
{
public string text { get; set; }
public string b1Tag { get; set; }
public string b2Tag { get; set; }
public string b3Tag { get; set; }
public URLListBoxCalss() { }
public URLListBoxCalss(string text, string b1Tag, string b2Tag, string b3Tag)
{
this.text = text;
this.b1Tag = b1Tag;
this.b2Tag = b2Tag;
this.b3Tag = b3Tag;
}
}