How do you guys pass the data (parameter) to the DataTemplate Selector?
The only thing I can think of is to use an attached property in the DataTemplate Selector?
Example:
public class DisableWeekendsSelection : DataTemplateSelector
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification = "DependencyProperty")]
public static readonly DependencyProperty Parameter =
DependencyProperty.RegisterAttached("Parameter", typeof(ObservableCollection<Date>), typeof(DisableWeekendsSelection),
new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static ObservableCollection<Date> GetParameter(DependencyObject dp)
{
return dp.GetValue(Parameter) as ObservableCollection<Date>;
}
public static void SetParameter(DependencyObject dp, ObservableCollection<Date> value)
{
dp.SetValue(Parameter, value);
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
The problem with this approach is that I cannot get the parameter value in the SelectTemplate method.
Any suggestion will be appreciated. Thanks in advance.
source
share