Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Wpf 绑定到xaml中的CollectionViewSource_Wpf_Xaml_Data Binding - Fatal编程技术网

Wpf 绑定到xaml中的CollectionViewSource

Wpf 绑定到xaml中的CollectionViewSource,wpf,xaml,data-binding,Wpf,Xaml,Data Binding,我有一个具有2个属性的ViewModel: IsReadOnly SomeCollectionViewSource 这是一个简单的工作视图示例: <StackPanel DataContext="{Binding SomeCollectionViewSource}"> <DatePicker SelectedDate="{Binding Path=Date}" IsEnabled="False" /> </StackPanel> 现在

我有一个具有2个属性的ViewModel:

  • IsReadOnly
  • SomeCollectionViewSource
这是一个简单的工作视图示例:

<StackPanel DataContext="{Binding SomeCollectionViewSource}">
  <DatePicker SelectedDate="{Binding Path=Date}" IsEnabled="False" />      
</StackPanel>

现在我想绑定IsEnabled属性:

<StackPanel DataContext="{Binding}">
  <DatePicker SelectedDate="{Binding Path=?}" IsEnabled="{Binding IsReadOnly}" />      
</StackPanel>

在本例中,绑定应该是什么样子?(我想我误解了一些简单的事情)
我更喜欢短而简单的绑定,因为我有很多控件要绑定


是否有更好/更简单的方法将一个CollectionViewSource上的所有控件设置为只读?

假设上述绑定以当前项为目标,则这应该是等效的:

{Binding SomeCollectionViewSource.View/Date}
另外,请参阅和的参考资料。如果您还没有阅读过这些参考资料,那么其中有很多内容

上述绑定(两个绑定中的一个)相当于:

{Binding Path=/Date}
斜杠可以省略,如果在集合中找不到该属性,则绑定将在当前项上查找该属性。所以

{Binding Date} binds to: CurrentItem -> Date
{Binding Count} binds to: Count
为了清楚起见,我建议总是明确地写斜杠


(顺便说一句,将任何
DataContext
设置为
{Binding}
都是毫无意义的)

谢谢,我从中学到了很多。空的DataContect绑定只是为了显示差异。现在我只是缺少了DatePicker上的IsReadOnly属性。我必须使用{Binding SomeCollectionViewSource.View/Date}@Roeland:噢,对了,如果CollectionViewSource设置为
Binding.source
(或DataContext),那么绑定是直接到源的,因为它位于属性路径中绑定将隐式地指向
视图
,因此在这些情况下,路径将仅为
/Data