0

你好朋友我遇到了在ListView Datatemplate中定義的TextBlock中顯示文本的問題,這裏是我的listview的代碼。ListView綁定ObservableCollection的KeyValuePair

<ListView Grid.Row="1" Margin="-2,0,0,-5" Padding="0" ItemContainerStyle="{StaticResource listviewItemSampleStyleWithNoselection}" ItemsSource="{Binding lst}" SelectionMode="None" > 
        <ListView.ItemTemplate> 
         <DataTemplate> 
          <Button FontSize="15" BorderThickness="0" Background="#8A69A7" > 
           <Button.ContentTemplate> 
            <DataTemplate> 
             <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Background="#8A69A7" > 
              <TextBlock Text="{Binding Path=Value}" FontSize="15" VerticalAlignment="Center" /> 
              <TextBlock x:Name="btnremoveSubject" Margin="10,0,-5,0" VerticalAlignment="Center" Padding="0" FontSize="15" Text="&#xE10A;" FontFamily="Segoe UI Symbol" Width="20" Height="18" HorizontalAlignment="Center" Foreground="White" FontWeight="Thin" /> 
             </StackPanel> 
            </DataTemplate> 
           </Button.ContentTemplate> 
          </Button> 
         </DataTemplate> 
        </ListView.ItemTemplate> 
        <ListView.ItemsPanel> 
         <ItemsPanelTemplate> 
          <VirtualizingStackPanel Orientation="Horizontal" /> 
         </ItemsPanelTemplate> 
        </ListView.ItemsPanel> 
       </ListView> 

這裏LST是我喜歡的類型KeyValuePair這裏的認定中的的ObservableCollection ..

public ObservableCollection<KeyValuePair<string,string>> lst { get; set; } 

在LST所有項目已填充了鍵和值。所以你們請指導我,我有什麼樣的幫助和建議表示讚賞。

+0

嘗試刪除的StackPanel和檢查。 –

+0

不能正常工作..但它沒有任何區別是堆棧面板是否或不.. – loop

回答

1

WinRT有問題。您無法綁定Dictionary<T,V>,ObservableCollection<KeyValuePair<T, V>>IEnumerable<KeyValuePair<T, V>>。您只有一個選擇是使用屬性作爲類的成員。

您也可以使用簡單的轉換器來檢測綁定是否正在發生。

Binding a Dictionary to a WinRT ListBox

Submitted bug

+1

我以爲我失去了一些東西..感謝:) – loop

+0

不客氣:) – Xyroid

相關問題