Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文件名字符串转换器的文件路径不工作_C#_Wpf_Xaml_Listbox_Converter - Fatal编程技术网

C# 文件名字符串转换器的文件路径不工作

C# 文件名字符串转换器的文件路径不工作,c#,wpf,xaml,listbox,converter,C#,Wpf,Xaml,Listbox,Converter,使用wpfListBox我试图在不显示完整路径的情况下显示文件名列表(对用户更方便) 数据来自使用对话框填充的可观察收集 private ObservableCollection<string> _VidFileDisplay = new ObservableCollection<string>(new[] {""}); public ObservableCollection<string> VidFileDisplay {

使用wpf
ListBox
我试图在不显示完整路径的情况下显示文件名列表(对用户更方便)

数据来自使用对话框填充的
可观察收集

    private ObservableCollection<string> _VidFileDisplay = new ObservableCollection<string>(new[] {""});

    public ObservableCollection<string> VidFileDisplay
    {
        get { return _VidFileDisplay; }
        set { _VidFileDisplay = value; }
    }
我将其绑定到我的listbox itemsource:

<ListBox x:Name="VideoFileList" Margin="0" Grid.Row="1" Grid.RowSpan="5" Template="{DynamicResource BaseListBoxControlStyle}" ItemContainerStyle="{DynamicResource BaseListBoxItemStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=DataContext.VidFileDisplay, Converter={StaticResource PathToFileName},ElementName=Ch_Parameters, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Path=SelectedVidNames,ElementName=Ch_Parameters, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
我错在哪里


感谢您

项目资源中
绑定转换器适用于整个列表
,而不是集合中的每个项目。如果要为每个项目应用转换器,则需要执行此操作
ItemTemplate

<ListBox x:Name="VideoFileList" ItemsSource="{Binding Path=DataContext.VidFileDisplay, ElementName=Ch_Parameters}" ...>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=., Converter={StaticResource PathToFileName}}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


项目资源中
绑定转换器适用于整个列表
而不是集合中的每个项目。如果要为每个项目应用转换器,则需要执行此操作
ItemTemplate

<ListBox x:Name="VideoFileList" ItemsSource="{Binding Path=DataContext.VidFileDisplay, ElementName=Ch_Parameters}" ...>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=., Converter={StaticResource PathToFileName}}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


就是这样。谢谢,就这样。非常感谢。
<ListBox x:Name="VideoFileList" ItemsSource="{Binding Path=DataContext.VidFileDisplay, ElementName=Ch_Parameters}" ...>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=., Converter={StaticResource PathToFileName}}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>