我有一个动态创建的列表视图,我已将SelectedIndex和ItemsSource属性绑定到我的ViewModel。我的模板有一个单选按钮,我已将IsChecked属性绑定到listview的IsSelected属性。现在我能够确定哪个项目选择哪个好,但在UI中,我无法检查单选按钮。这显然是与UI相关的问题。有什么建议?我的代码如下:
<ListView Height="330" HorizontalAlignment="Stretch" SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}" Name="idleTimeoutAppListView" ItemsSource="{Binding listViewEntries}" SelectionChanged="ItemSelected" Margin="15,15,15,0" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel HorizontalAlignment="Stretch" Width="auto">
<TextBlock Text="{Binding TextProp,Mode=TwoWay}" Margin="10,0,0,0"/>
<RadioButton GroupName="radioButtonGroup" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalContentAlignment="Center" IsChecked="{Binding Path=IsSelected, Mode=TwoWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}">
<RadioButton.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2"/>
</RadioButton.LayoutTransform>
</RadioButton>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
答案 0 :(得分:0)
删除了SelectionChanged事件并绑定了selecteditem事件,现在工作正常。但是我的列表视图项目无法再次选择