« RadioButton » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 74 : | Ligne 74 : | ||
</DockPanel> | </DockPanel> | ||
<!-- --> | <!-- ToggleButton --> | ||
<Grid Background="{TemplateBinding Background}"> | <Grid Background="{TemplateBinding Background}"> | ||
<ToggleButton IsChecked="{TemplateBinding IsSelected}" | <ToggleButton IsChecked="{TemplateBinding IsSelected}" |
Version du 30 mai 2022 à 16:29
DevExpress ListBoxEdit avec un style RadioButton
ListBox avec un style RadioButton
<ListBox SelectedIndex="{Binding Mode, Mode=TwoWay}" Style="{StaticResource HorizontalRadioButtonList}"> <ListBoxItem Content="Mode 1" /> <ListBoxItem Content="Mode 2" /> <ListBoxItem Content="Mode 3" /> </ListBox> |
public Mode Mode { get => mode; set => SetProperty(ref mode, value); } enum Mode { Mode1, Mode2, Mode3 } |
<Style x:Key="RadioButtonHorizontalListBox" TargetType="ListBox"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBox}"> <Border BorderThickness="1,0,0,0" BorderBrush="{TemplateBinding BorderBrush}"> <ItemsPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ListBoxItem"> <Setter Property="BorderBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox, AncestorLevel=1}}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <!-- RadioButton --> <DockPanel Background="{TemplateBinding Background}"> <RadioButton IsChecked="{TemplateBinding IsSelected}" Focusable="False" IsHitTestVisible="False" VerticalAlignment="Center" Margin="0,0,4,0" /> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </DockPanel> <!-- ToggleButton --> <Grid Background="{TemplateBinding Background}"> <ToggleButton IsChecked="{TemplateBinding IsSelected}" Content="{TemplateBinding Content}" Padding="10,5" BorderThickness="0,1,1,1" BorderBrush="{TemplateBinding BorderBrush}" Focusable="False" IsHitTestVisible="False" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> </Style> |