【问题标题】:WPF ComboBox ItemTemplate binding to a string collectionWPF ComboBox ItemTemplate 绑定到字符串集合
【发布时间】:2014-11-26 03:25:34
【问题描述】:

我在 wpf 中有一个组合框,它绑定到 List<string>。一切正常,但现在由于某种原因我需要绑定到项目模板。组合框的 XAML 是

<ComboBox ItemsSource="{Binding Tracks}" SelectedItem="{Binding SelectedTrack}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding **WhatShouldBeHere**}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

如果我的数据源是自定义集合,那么绑定很容易,我应该只从自定义集合中传递属性名称,但是由于绑定源是字符串列表,那么绑定属性应该是什么?

【问题讨论】:

    标签: wpf xaml data-binding combobox


    【解决方案1】:

    应该是

    <TextBlock Text="{Binding}"/>
    

    相当于

    <TextBlock Text="{Binding Path=.}"/>
    

    有关详细信息,请参阅Binding.Path MSDN 页面上的备注部分。

    【讨论】:

      猜你喜欢
      • 2010-09-17
      • 2013-10-11
      • 2011-10-14
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      • 2015-08-23
      相关资源
      最近更新 更多