Wpf listview项目模板绑定

Wpf listview项目模板绑定,wpf,xaml,binding,Wpf,Xaml,Binding,我写了这样的东西 <ListView Background="{x:Null}" ItemsSource="{Binding Source={StaticResource Foos},Path=FooList}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"> <ListView.ItemTemplate> <Da

我写了这样的东西

<ListView Background="{x:Null}" ItemsSource="{Binding Source={StaticResource Foos},Path=FooList}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBox Text="{Binding Path=Name}" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
                        <ComboBox Grid.Column="1" Background="{x:Null}" VerticalAlignment="Center" HorizontalAlignment="Stretch">
                            <ComboBox.Items>
                                <sys:String>First</sys:String>
                                <sys:String>Second</sys:String>
                                <sys:String>Third</sys:String>
                                <sys:String>Fourth</sys:String>
                            </ComboBox.Items>
                            <ComboBox.SelectedItem>
                                <Binding Converter="{StaticResource FooTypeToStringConverter}"/> <-- this causes an error -->
                            </ComboBox.SelectedItem>
                        </ComboBox>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
所以这不是我的原因

我想我做了些蠢事,但我不知道-什么。你能帮我吗

<Binding Converter="{StaticResource FooTypeToStringConverter}"/> <-- this causes an error -->

根据你发布的警告
System.Windows.Data警告:58:路径:“”
Path
属性设置为空。这意味着您必须设置它。通常你可以这样做:

public class FooTypeToStringConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        //Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => { MessageBox.Show(value.GetType().ToString()); }));
        return Binding.DoNothing;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
SelectedItem="{Binding}"
这也意味着与

SelectedItem = "{Binding DataContext,RelativeSource={RelativeSource Self}}"/>
和转换器:

SelectedItem = "{Binding DataContext,RelativeSource={RelativeSource Self}}, Converter="{StaticResource FooTypeToStringConverter}"

您也可以使用
ObservableCollection
而不是
BindableList

您是否在XAML中声明了FooTypeToStringConverter?您说您得到了一个异常:哪一个?请粘贴异常stacktrace,如果您在xaml中声明了FootTypeToStringConverter,是否使用了正确的命名空间,或者声明是否也会导致错误(蓝色下划线)?我认为XAML窗口资源中的键(x:key)不是“FooTypeToStringConverter”。您是否也可以发布?如果是绑定错误,您可以使用绑定中的System.Diagnostics.PresentationTraceSources.TraceLevel=“High”获取其他信息
System.Windows.Data Warning: 56 : Created BindingExpression (hash=14506096) for Binding (hash=28492826)
System.Windows.Data Warning: 58 :   Path: ''
System.Windows.Data Warning: 60 : BindingExpression (hash=14506096): Default mode resolved to TwoWay
System.Windows.Data Warning: 61 : BindingExpression (hash=14506096): Default update trigger resolved to PropertyChanged
SelectedItem="{Binding}"
SelectedItem = "{Binding DataContext,RelativeSource={RelativeSource Self}}"/>
SelectedItem = "{Binding DataContext,RelativeSource={RelativeSource Self}}, Converter="{StaticResource FooTypeToStringConverter}"