列表框中的 ObservableCollection 图像到内容控制主详细信息 WPf
我有一个通过以下代码填充的可观察图像集合:
<StackPanel Orientation="Horizontal" Grid.Column="0">
<ListBox ItemsSource="{Binding BigImageView}" IsSynchronizedWithCurrentItem="True"
SelectedIndex="0" SelectedItem="{Binding CurrentItem}" />
</StackPanel>
<ContentControl Name="Detail" Content="{Binding BigImageView, Mode=OneWay}"
Margin="9,0,0,0" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top"/>
但是内容控件应该通过 ObservableCollection 绑定到 BigImageView
BigImage = new ObservableCollection<Image>();
_listView = CollectionViewSource.GetDefaultView(BigImage);
_listView.CurrentChanged += new EventHandler(OnCurrentChanged);
public System.ComponentModel.ICollectionView BigImageView
{
get
{
return _listView;
}
set
{
_listView = value;
OnPropertyChanged("BigImageView");
}
}
我想在移动列表框时将图像返回到内容控件。我绞尽脑汁,想尽一切办法,但还是不行。任何帮助将不胜感激。
I have an observablecollection of Images that get populated via the following code:
<StackPanel Orientation="Horizontal" Grid.Column="0">
<ListBox ItemsSource="{Binding BigImageView}" IsSynchronizedWithCurrentItem="True"
SelectedIndex="0" SelectedItem="{Binding CurrentItem}" />
</StackPanel>
<ContentControl Name="Detail" Content="{Binding BigImageView, Mode=OneWay}"
Margin="9,0,0,0" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top"/>
However the Content Control is supposed to bind to the BigImageView via an ObservableCollection
BigImage = new ObservableCollection<Image>();
_listView = CollectionViewSource.GetDefaultView(BigImage);
_listView.CurrentChanged += new EventHandler(OnCurrentChanged);
public System.ComponentModel.ICollectionView BigImageView
{
get
{
return _listView;
}
set
{
_listView = value;
OnPropertyChanged("BigImageView");
}
}
I want to return the image to the content control when I move the listbox. I have been racking my brain and trying everyhitn but it does not work. any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要绑定所选项目,collectionview 应该处理这个问题。
试试这个:
There is no need to bind the selecteditem, the collectionview should take care of that.
Try this:
1
创建一个包含列表和所选项目的视图模型:
在构造函数中在控件的 DataContext 上设置此对象:
将 ListBox ItemsSource 设置为 BigImage 列表,将 SelectedItem 绑定到 BigImageView
并在内容控件中使用它:
ContentControl:
2
或者拧紧视图模型:
直接在构造函数中设置列表(在 InitializeComponent() 之后):
为列表命名:
并使用 ElementName 绑定到您所选的项目:
1
Create a viewmodel with a list and a selected item:
Set this object on the DataContext of your control in the constructor:
Set the ListBox ItemsSource to your BigImage list, bind your SelectedItem to BigImageView
and use that in your content control:
ContentControl:
2
Or screw that view model:
Set the list directly in the constructor (after the InitializeComponent() ):
Give the list a name:
And bind with an ElementName binding to your selected item: