首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

关于在listbox中datatemplate绑定command的有关问题

2012-04-16 
关于在listbox中datatemplate绑定command的问题程序应用MVVM,当前view的DataContextviewModel.在viewmodl

关于在listbox中datatemplate绑定command的问题
 



程序应用MVVM,当前view的DataContext=viewModel.在viewmodle里有downloadCommand.请问我在XMAL里应该如何绑定?

<gpfControls:GpfListBox ItemsSource="{Binding Path=FileNames,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Width="380" Height="25" VerticalAlignment="Bottom" ScrollViewer.VerticalScrollBarVisibility="Disabled">
  <gpfControls:GpfListBox.ItemTemplate>
  <DataTemplate>
  <gpfControls:GpfTextBlock>
  <gpfControls:GpfHyperlink Command="{Binding DownLoadCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}" TextDecorations="{x:Null}">
  <gpfControls:GpfTextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"/>
  </gpfControls:GpfHyperlink>
  </gpfControls:GpfTextBlock>
  </DataTemplate>
  </gpfControls:GpfListBox.ItemTemplate>
  </gpfControls:GpfListBox>




[解决办法]
<gpfControls:GpfListBox ItemsSource="{Binding Path=FileNames,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Width="380" Height="25" VerticalAlignment="Bottom" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<gpfControls:GpfListBox.ItemTemplate>
<DataTemplate>
<gpfControls:GpfTextBlock>
<gpfControls:GpfHyperlink Command="{Binding DownLoadCommand}" CommandParameter="{Binding [del]RelativeSource={RelativeSource Self}, Path=DataContext}"[/del] TextDecorations="{x:Null}">
<gpfControls:GpfTextBlock Text="{Binding TextRelativeSource={RelativeSource Self}, Path=DataContext}"/>
</gpfControls:GpfHyperlink>
</gpfControls:GpfTextBlock>
</DataTemplate>
</gpfControls:GpfListBox.ItemTemplate>
</gpfControls:GpfListBox>
[解决办法]
1楼给出提示了,command绑定不需要带入commandparameter参数,直接绑定path就可以实现。

请参考:

http://silverlightchina.net/html/study/WPF/2011/0715/9033.html

http://silverlightchina.net/html/study/WPF/2011/0715/9034.html

http://silverlightchina.net/html/study/WPF/2011/0715/9035.html

http://silverlightchina.net/html/tips/2011/1020/11126.html

http://silverlightchina.net/html/tips/2011/1031/11406.html

热点排行