C# 将CollectionViewSource绑定到内部类
我想将内部ObservableCollection绑定到CollectionViewSource,以便对其应用过滤器。但不幸的是,我第一步就失败了。我无法将我的集合作为新资源绑定到collectionViewSource。我用works fine替换了以下代码:C# 将CollectionViewSource绑定到内部类,c#,C#,我想将内部ObservableCollection绑定到CollectionViewSource,以便对其应用过滤器。但不幸的是,我第一步就失败了。我无法将我的集合作为新资源绑定到collectionViewSource。我用works fine替换了以下代码: <DataGridTemplateColumn x:Key="MyComboBoxFunctionColumn" Header="Function"> <DataGridTemplateColu
<DataGridTemplateColumn x:Key="MyComboBoxFunctionColumn" Header="Function">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Mux.Setting.FunctionList}" DisplayMemberPath="Name" SelectedIndex="{Binding Mux.Setting.Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Mux.Applicable}" IsReadOnly="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
使用新的collection类,但不幸的是,现在我的combobox项是空的,但我不知道为什么
<CollectionViewSource x:Key="src" Source="{Binding Path=Mux.Setting.FunctionList}" >
<DataGridTemplateColumn x:Key="MyComboBoxFunctionColumn" Header="Function">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource src}}" DisplayMemberPath="Name" SelectedIndex="{Binding Mux.Setting.Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Mux.Applicable}" IsReadOnly="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
enter code here
欢迎任何能解决我问题的建议
提前谢谢你 VS的“输出”窗格应告诉您在什么类型的对象上未找到此类属性。感谢Aybe的提示,但没有警告,列出错误。尝试使用Snoop软件检查对象的属性。嗨,Aybe,Snoop没有发现此元素的绑定错误:-通常我会用我告诉您的两个提示来解决绑定问题,所以不确定您这方面发生了什么。您应该发布一个完整的代码示例,因为您提供的示例不完整,我们无法仅从您发布的内容中帮助您。
public PortMux PortMux
{
get { return (PortMux)GetValue(PortMuxProperty); }
set { SetValue(PortMuxProperty, value); }
}
public static readonly DependencyProperty PortMuxProperty =
DependencyProperty.Register("PortMux", typeof(PortMux), typeof(MainWindow), new UIPropertyMetadata(null));...
public partial class MainWindow : Window
{...
PortMux = new PortMux();
...
PortMux = projectRef;
..
base.DataContext = this;
InitializeComponent();
<CollectionViewSource x:Key="src" Source="{Binding Path=Mux.Setting.FunctionList}" >
<DataGridTemplateColumn x:Key="MyComboBoxFunctionColumn" Header="Function">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource src}}" DisplayMemberPath="Name" SelectedIndex="{Binding Mux.Setting.Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Mux.Applicable}" IsReadOnly="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
enter code here