【发布时间】:2014-01-02 17:10:34
【问题描述】:
我有以下视图模型的 xaml 和代码,目前我将屏幕列表视图绑定到视图模型。 用户控件有文本框和按钮,当用户单击按钮(Go)时,我想从视图中获取数据,我应该怎么做?
目前我总是在运行窗口时获取数据,但是
我希望在打开页面和单击时列表为空 GO按钮列表将被填充
<Grid Width="877" Height="632"
DataContext="{Binding Source={StaticResource ConfigServiceModelViewDataSource}}" >
<Grid.ColumnDefinitions>
<UserControl.Resources>
<ViewModel:ConfigServiceModelView x:Key="ConfigServiceModelViewDataSource" />
<DataTemplate x:Key="CollectionTemplate">
</DataTemplate>
</UserControl.Resources>
<ListView Grid.Column="2" HorizontalAlignment="Center" Height="230"
Margin="5,20,0,0" Grid.Row="2" VerticalAlignment="Top" Width="330"
ItemsSource="{Binding GetCollection}" }" >
<Button Content="Go" Grid.Column="3" Grid.Row="1" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="75" Height="21.96" />
在 ModelView 我从模型中获取数据,比如
internal class ConfigModelView {
private ConfigServiceModel _configServiceModel = new ConfigServiceModel();
public List<string> GetServiceCollection {
get {
return _configServiceModel.CollectList;
}
}
}
【问题讨论】:
-
I want to get the data from the view ,how should I do that- 使用数据绑定。顺便说一句,你的问题完全不清楚,你能澄清一下吗? -
在这种情况下,仅在单击按钮时才填充您的列表。
-
@HighCore- 已更新,希望现在清楚...