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