WPF 用ListBox实现RadioGroup的效果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<GroupBox Grid.Row="2" Header="类型">
            <ListBox ItemsSource="{Binding roomTypeLists}" SelectedItem="{Binding selectedType, UpdateSourceTrigger=PropertyChanged}">
                <ListBox.Template>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                            <WrapPanel IsItemsHost="True"
                                       Orientation="Horizontal"
                                       ScrollViewer.CanContentScroll="True" />
                        </ScrollViewer>
                    </ControlTemplate>
                </ListBox.Template>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <RadioButton Content="{Binding Path=content}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>

            </ListBox>

        </GroupBox>
Licensed under CC BY-NC-SA 4.0
记录平时瞎折腾遇到的各种问题, 方便查找
使用 Hugo 构建
主题 Stack 3.29.0Jimmy 设计