Windows Presentation Foundation - FAQ
As usual, I came accros this while "googlng" for way to implement a radio group in WPF using the MVVM model. Essentially, it is a collection of FAQs in WPF. The original post can be found here.
<
Page
xmlns
=
"
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="
http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s
="
clr-namespace:System;assembly=mscorlib"
>
<
Page.Resources
>
<
x:Array
Type
="
{x:Type s:String}"
x:Key
="
data"
>
<
s:String
>Option1
</
s:String
>
<
s:String
>Option2
</
s:String
>
<
s:String
>Option3
</
s:String
>
</
x:Array
>
</
Page.Resources
>
<
StackPanel
DataContext
="
{StaticResource data}"
>
<
TextBlock
Margin
="
5"
>
<
TextBlock
Text
="
Current Option:"
/>
<
TextBlock
Text
="
{Binding /}"
/>
</
TextBlock
>
<
ListBox
ItemsSource
="
{Binding}"
IsSynchronizedWithCurrentItem
="
True"
Width
="
240"
Height
="
60"
HorizontalAlignment
="
Left"
>
<
ListBox.ItemContainerStyle
>
<
Style
TargetType
="
{x:Type ListBoxItem}"
>
<
Setter
Property
="
Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
="
{x:Type ListBoxItem}"
>
<
RadioButton
IsChecked
="
{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
Content
="
{TemplateBinding Content}"
/>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
ListBox.ItemContainerStyle
>
</
ListBox
>
</
StackPanel
>
</
Page
>
Comments
Post a Comment