2
我正在使用Listbox,它包含按鈕,並且我想使用command.but我的命令處理按鈕單擊事件。如何在Silverlight4中的列表框中調用命令
是這樣正確嗎?
<pmControls:pmListBox Grid.Row="1" Margin="3" ItemsSource="{Binding Countries}" SelectedItem="{Binding SelectedCountry}" >
<pmControls:pmListBox.ItemTemplate >
<DataTemplate >
<Button Command="{Binding GetAllStatesCommand}" CommandParameter="{Binding}" Margin="3" Width="100" Height="50" Content="{Binding Title}">
</Button>
</DataTemplate>
</pmControls:pmListBox.ItemTemplate>
</pmControls:pmListBox>
感謝它的作品,但現在我的命令調用,但又失去了我給列表框的先前綁定:ItemsSource =「{Binding Countries}」SelectedItem =「{Binding SelectedCountry}」,我沒有得到選擇對象? – Gayatri
請參閱我的修改答案 - 如果綁定了ID,您當然只會將該項目作爲命令參數。無論你在代碼中找到''[...]'我給你留下了一些提高可讀性的東西...... – Spontifixus