【问题标题】:ListView Binding With ObservableCollection of KeyValuePairListView 与 KeyValuePair 的 ObservableCollection 绑定
【发布时间】:2013-10-16 12:58:46
【问题描述】:

您好朋友,我遇到了在 ListView Datatemplate 中定义的 TextBlock 中显示文本的问题,这是我的 listview 的代码。

<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>

这里是我的 KeyValuePair 类型的 ObservableCollection,这里是它的定义..

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

lst 中的所有项目都已经填充了键和值。所以请你们指导我有什么帮助和建议。

【问题讨论】:

  • 尝试删除 StackPanel 并检查它。
  • 不工作..但它没有任何区别是stackpanel是否是thr..

标签: listview windows-8 windows-runtime microsoft-metro winrt-xaml


【解决方案1】:

WinRT 有错误。您无法绑定Dictionary&lt;T,V&gt;ObservableCollection&lt;KeyValuePair&lt;T, V&gt;&gt;IEnumerable&lt;KeyValuePair&lt;T, V&gt;&gt;。您只有一种选择是使用属性作为类的成员。

您还可以使用简单的转换器进行测试,以检查是否发生绑定。

Binding a Dictionary to a WinRT ListBox

Submitted bug

【讨论】:

    猜你喜欢
    • 2011-08-27
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 2012-05-26
    • 2018-05-21
    相关资源
    最近更新 更多