« RadioButton » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
|||
Ligne 1 : | Ligne 1 : | ||
[[Category:WPF]] | [[Category:WPF]] | ||
= [[ListBoxEdit#Style_RadioButton|DevExpress ListBoxEdit avec un style RadioButton]] = | = [[ListBoxEdit#Style_RadioButton|DevExpress ListBoxEdit avec un style RadioButton]] = | ||
= [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'> | ||
Ligne 7 : | Ligne 8 : | ||
<ListBoxItem>Choix2</ListBoxItem> | <ListBoxItem>Choix2</ListBoxItem> | ||
</ListBox> | </ListBox> | ||
<ListBox SelectedIndex="{Binding Mode, Mode=TwoWay}" | |||
Style="{StaticResource HorizontalRadioButtonList}"> | |||
<ListBoxItem Content="Mode 1" /> | |||
<ListBoxItem Content="Mode 2" /> | |||
<ListBoxItem Content="Mode 3" /> | |||
</ListBox> | |||
</kode> | |||
<kode lang='cs'> | |||
public Mode Mode | |||
{ | |||
get => mode; | |||
set => SetProperty(ref mode, value); | |||
} | |||
enum Mode | |||
{ | |||
Mode1, | |||
Mode2, | |||
Mode3 | |||
} | |||
</kode> | </kode> | ||
<kode lang='xaml'> | <kode lang='xaml'> | ||
<Style x:Key="RadioButtonList" TargetType="ListBox"> | <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.Resources> | ||
<Style TargetType="Label"> | <Style TargetType="Label"> | ||
Ligne 18 : | Ligne 70 : | ||
<Setter Property="BorderThickness" Value="0" /> | <Setter Property="BorderThickness" Value="0" /> | ||
<Setter Property="Background" | <Setter Property="Background" Value="Transparent" /> | ||
<Setter Property="ItemContainerStyle" Value="{StaticResource RadioButtonListItem}" /> | <Setter Property="ItemContainerStyle" Value="{StaticResource RadioButtonListItem}" /> | ||
Ligne 38 : | Ligne 90 : | ||
</Style> | </Style> | ||
<Style x:Key="HorizontalRadioButtonList" BasedOn="{StaticResource RadioButtonList}" TargetType="ListBox"> | <Style x:Key="HorizontalRadioButtonList" | ||
BasedOn="{StaticResource RadioButtonList}" | |||
TargetType="ListBox"> | |||
<Setter Property="ItemsPanel"> | <Setter Property="ItemsPanel"> | ||
<Setter.Value> | <Setter.Value> | ||
<ItemsPanelTemplate> | <ItemsPanelTemplate> | ||
<VirtualizingStackPanel Background="Transparent" Orientation="Horizontal" /> | <VirtualizingStackPanel Background="Transparent" | ||
Orientation="Horizontal" /> | |||
</ItemsPanelTemplate> | </ItemsPanelTemplate> | ||
</Setter.Value> | </Setter.Value> | ||
</Setter> | </Setter> | ||
</Style> | </Style> | ||
</kode> | </kode> |
Version du 30 mai 2022 à 10:06
DevExpress ListBoxEdit avec un style RadioButton
ListBox avec un style RadioButton
<ListBox Style="{StaticResource HorizontalRadioButtonList}" SelectedValue="{Binding Selection}"> <ListBoxItem>Choix1</ListBoxItem> <ListBoxItem>Choix2</ListBoxItem> </ListBox> <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> |