0
我有一個堆棧面板與多個文本塊綁定到解析XML文件的結果。我可以使TextBlock可點擊 - 基於XML解析結果嗎?
我想讓每個結果都有一個onlick事件,然後鏈接到更多信息甚至message.show框,但它必須使用它顯示的結果中的值。
這對於disaplys結果列表框的.XAML部分。)
<ListBox Height="435"
HorizontalAlignment="Left"
Name="TradeSearch1"
VerticalAlignment="Top"
Width="397"
Grid.ColumnSpan="3"
Margin="0,63,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Height="200">
<Image Source="{Binding ImageSource}"
Height="150" Width="150"
VerticalAlignment="Top"
Margin="0,10,8,0"/>
<StackPanel Width="370" >
<TextBlock Text="{Binding Title}"
TextWrapping="Wrap"
Foreground="#FFE51A1A"
FontSize="16" />
<TextBlock Text="{Binding PriceDisplay}"
TextWrapping="Wrap"
FontSize="20"
Foreground="Black" />
<TextBlock Text="{Binding ListingId}"
TextWrapping="Wrap"
FontSize="20"
Foreground="Black" />
<TextBlock Text="{Binding Region}"
TextWrapping="Wrap"
FontSize="18"
Foreground="Black" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
其中一個文本塊的返回(ListingID)的值。理想情況下,當用戶點擊這個結果時,他們會被帶到另一個頁面,根據結果得到的LIstingID表單,這個頁面會取消更多的結果。
上市ID爲400332970
有沒有辦法到價值攜帶到另一個頁面,並在這樣的使用呢?其中ListingID.XMl將成爲onClick結果中的listingId。
WebClient Trademe = new WebClient();
Trademe.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
Trademe.DownloadStringAsync(new Uri("http://api.trademe.co.nz/v1/Listings/" + ListingID.xml));
對不起,如果這是令人困惑,我試圖盡我所能解釋。希望有人知道我在說什麼。
會不會通過所有listingID的?而不是用戶點擊的那個?有大約20個不同的列表都與他們自己ListingID – Rhys
@Rhys:不,它不會。推測你將ListBox的ItemSource綁定到代碼後面的某個集合。上面的答案中提到的'myObject'是該集合中的一個對象。因此,對應於ListBox的選定項目的對象將僅包含被輕擊的ListBoxItem的列表ID。 – Praetorian
@keyboardP好吧,聽起來像是我的解決方案。我不明白用對象類型替換我的對象?你的意思是String,Bool等? – Rhys