I'm using Caliburn.Micro in my app. What I want to do is:
- Create one RadioButton per available licence in the View
- Check the one whose licence is currently active
So far I have two properties on my ViewModel (I'm leaving out INotify...Changed
and its implementations here because that works):
BindableCollection<LicenceInfo> AvailableLicences { get; set; }
LicenceInfo ActiveLicence { get; set; }
In the ViewModel's constructor, I populate AvailableLicences
and ActiveLicence
. So far, so good.
Currently in the View itself, I have an ItemsControl
which contains the RadioButton
s and an invisible FrameworkElement
to pass to MyConverter
, where I extract the DataContext
s of Self
and the invisible FrameworkElement
(whose DataContext
is bound to the ViewModel) and compare them with (overridden) LicenceInfo.Equals()
:
<FrameworkElement Name="ActiveLicence" Visibility="Collapsed" />
<ItemsControl Name="AvailableLicences">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton cal:Message.Attach="[Event Checked] = [Action ChangeActiveLicence($dataContext)]">
<RadioButton.IsChecked>
<MultiBinding Converter="{StaticResource MyConverter}" Mode="OneWay">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding ElementName="ActiveLicence" />
</MultiBinding>
</RadioButton.IsChecked>
[...]
This actually works as intended, but it seems to me like an ugly workaround and I'm sure that I'm missing something.
Using <Binding x:Name="ActiveLicence" />
or <Binding Path="ActiveLicence" />
as the second parameter and removing the invisible FrameworkElement
does not work, the ViewModel property is not being attached to the binding.
I'm not necessarily tied to using a MultiBinding
. Anything similar to the Caliburn.Micro action like the one handling the Checked
event would be welcome too. Any ideas?