WPF的ListBox中的RadioButton不能单选问题

WPF不知道是微软故意弄的还是真的匆忙的推出的产品,在实际开发过程中有很多小问题解决很麻烦。

今天主要说一下ListBox中使用RadioButton的时候里面的RadioButton不能单选!居然成复选了。。。

至于为什么用ListBox而不是GroupBox或者Grid什么的 ,主要是ListBox可以绑定数据。

上代码:

 <ControlTemplate x:Key="ListBoxControlTemplate" TargetType="ListBoxItem">
            <RadioButton IsChecked="{Binding Path=IsSelected,
            RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}">
                <ContentPresenter></ContentPresenter>
            </RadioButton>
  </ControlTemplate>


<ListBox Height="299"  DisplayMemberPath="Text" HorizontalAlignment="Left" Margin="105,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="296">
            <ListBox.ItemContainerStyle>
                <Style>
                    <Setter Property="ListBoxItem.Template" Value="{StaticResource ListBoxControlTemplate}">
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>

如上,仅仅更改了listbox的ControlTemplate。

.Net、ArcGIS交流学习群:94234450
不管你遇到了什么问题,我们绝不会让你独自去面对!

原文地址:https://www.cnblogs.com/BeiJing-Net-DaiDai/p/4110908.html