Expression Blend 中的数据绑定新手
我在 Expression Blend 中有一个 WPF 应用程序。
在应用程序中,我想在右侧有一个列出单词的列表框。
当用户单击一个单词时,我想在左侧显示该单词的更大文本、描述和其他一些文本。
据我所知,要列出列表框中的所有单词,我需要对包含单词、描述和其他文本的数据进行数据绑定。
我是这个数据绑定的新手。
有人可以帮我如何在 Expression Blend 4 中执行此操作吗?
谢谢!
I have a WPF application in Expression Blend.
In the application I want to have a listbox on the right side that lists words.
When the user clicks on a word, I want to appear on the left a bigger text of the word, description, and some other text.
I understand that to list all the words in the listbox I need to databind data that contains the words, description and other text.
I'm new to this data binding.
Can someone please help me how to do this in Expression Blend 4?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我构建了一个非常基本的 MVVM 示例,它将向您展示一些基本功能。
我首先创建了一个“汽车”对象。这就是我的列表框将包含的内容。
Car.cs
接下来,我创建了一个 ViewModel 以设置为视图的 DataContext。 ViewModel 有两个属性:“Cars”和“SelectedCar”。视图将绑定到这两个属性。这是 ViewModel 的实现。
MainWindow_ViewModel.cs
现在,在视图中,我能够创建一个 ListBox(就像您建议的那样)并用我的汽车列表填充它的 ItemSource。我还将 ListBox 的 SelectedItem 绑定到 ViewModel 上的 SelectedCar。我在视图中放置了一些其他文本,以显示有关所选汽车的更多数据。
MainWindow.xaml
当您在 ListBox 中选择一个项目时,它将更新 ViewModel 上的 SelectedItem,因此,它会更新绑定到 SelectedCar 上的属性的 TextBlock。
我认为这与您想要实现的目标类似。希望这有帮助!
I built a very basic MVVM example that will show you some of the basic functionality.
I first created a 'Car' object. This is what my listbox will contain.
Car.cs
Next, I created a ViewModel to set as the DataContext of my view. The ViewModel has two properties, 'Cars' and 'SelectedCar'. The view will bind to these two properties. Here's the implementation of the ViewModel.
MainWindow_ViewModel.cs
Now, in the view, I was able to create a ListBox (like you suggested) and populate it's ItemSource with my list of Cars. I also bound the SelectedItem of the ListBox to the SelectedCar on the ViewModel. I placed some other text in the View to show more data about the selected Car too.
MainWindow.xaml
When you select an item in the ListBox, it will update the SelectedItem on the ViewModel, therefore, it updates the TextBlocks that are bound to the properties on the SelectedCar.
I think this is something similar to what you are trying to accomplish. Hope this helps!