論理的に関連する RadioButton のリストを作成したいと考えています。RadioButton は、MVVM で使用するためにバインドされています。各 RadioButton にツールチップがあります。
1 に答える
1
ListBox を使用して、論理的に関連する RadioButton のグループを作成する Style を次に示します。MyClass には、MyName と MyToolTip の 2 つの String プロパティが含まれています。スタイルは、適切に機能する個々のツールチップを含む RadioButton のリストを表示します。これは、MVVM で使用するためのすべてバインドされたすべての Xaml ソリューションです。
使用例:
ListBox Style="{StaticResource radioListBox}" ItemsSource="{Binding MyClasses}" SelectedValue="{Binding SelectedMyClass}"/>
スタイル:
<Style x:Key="radioListBox" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="5" />
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="Transparent">
<RadioButton Focusable="False" IsHitTestVisible="False" IsChecked="{TemplateBinding IsSelected}" Content="{Binding MyName}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ToolTip" Value="{Binding MyToolTip}" />
</Style>
</Setter.Value>
</Setter>
</Style>
于 2010-06-12T15:36:00.567 に答える