« RadioButton » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
|||
Ligne 4 : | Ligne 4 : | ||
= [http://stackoverflow.com/questions/1317891/simple-wpf-radiobutton-binding ListBox avec un style RadioButton] = | = [http://stackoverflow.com/questions/1317891/simple-wpf-radiobutton-binding ListBox avec un style RadioButton] = | ||
<kode lang='xaml'> | <kode lang='xaml'> | ||
<ListBox SelectedIndex="{Binding Mode, Mode=TwoWay}" | <ListBox SelectedIndex="{Binding Mode, Mode=TwoWay}" | ||
Style="{StaticResource HorizontalRadioButtonList}"> | Style="{StaticResource HorizontalRadioButtonList}"> |
Version du 30 mai 2022 à 10:06
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="RadioButtonListItem" TargetType="{x:Type ListBoxItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <DockPanel LastChildFill="True" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" VerticalAlignment="Center"> <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> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="RadioButtonList" TargetType="ListBox"> <Style.Resources> <Style TargetType="Label"> <Setter Property="Padding" Value="0" /> </Style> </Style.Resources> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="ItemContainerStyle" Value="{StaticResource RadioButtonListItem}" /> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBox}"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextBlock.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> </Trigger> </Style.Triggers> </Style> <Style x:Key="HorizontalRadioButtonList" BasedOn="{StaticResource RadioButtonList}" TargetType="ListBox"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <VirtualizingStackPanel Background="Transparent" Orientation="Horizontal" /> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> |