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

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

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

至于为何用ListBox而不是GroupBox或者Grid什么的 ,主要是ListBox能够绑定数据。code

上代码:blog

 <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
无论你遇到了什么问题,咱们毫不会让你独自去面对!get

相关文章
相关标签/搜索