private void Child_ChildAdded(object sender, ElementEventArgs e)
{
var sfChip = e.Element as SfChip;
if (sfChip != null)
{
. . .
var dataContext = GetInternalProperty(typeof(SfChip), sfChip, "DataContext");
sfChip.SetBinding(SfChip.ShowSelectionIndicatorProperty,
new Binding()
{
Path = CheckMemberPath,
Mode = BindingMode.TwoWay,
Source = dataContext
});
}
}
. . .
. . .
public static object GetInternalProperty(Type type, object obj, string propertyName)
{
var property = type.GetTypeInfo().GetDeclaredProperty(propertyName);
if (property != null)
{
return property.GetValue(obj);
}
return null;
} |
public class CustomChipGroup : SfChipGroup
{
public CustomChipGroup() : base()
{
SelectedItems = new ObservableCollection<object>();
}
private void Child_ChildAdded(object sender, ElementEventArgs e)
{
var sfChip = e.Element as SfChip;
if (sfChip != null)
{
var dataContext = GetInternalProperty(typeof(SfChip), sfChip, "DataContext") as Word;
if (dataContext.IsSelected)
SelectedItems.Add(dataContext);
}
}
} |
private void Child_ChildAdded(object sender, ElementEventArgs e)
{
var sfChip = e.Element as SfChip;
if (sfChip != null)
{
sfChip.SetBinding(SfChip.CornerRadiusProperty, new Binding() { Path = "CornerRadius", Source = this, Mode = BindingMode.TwoWay });
var dataContext = GetInternalProperty(typeof(SfChip), sfChip, "DataContext") as Word;
sfChip.SetBinding(SfChip.ShowSelectionIndicatorProperty,
new Binding()
{
Path = CheckMemberPath,
Mode = BindingMode.TwoWay,
Source = dataContext
});
sfChip.SetBinding(SfChip.BackgroundColorProperty, new Binding()
{
Path = "SelectedChipBackgroundColor",
Source = this,
});
}
} |
public class SelectedColorConverter : IValueConverter
{
public Color SelectedBackgroundColor { get; set; }
public Color BackgroundColor { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value != null)
{
if ((bool)value)
return SelectedBackgroundColor;
}
return BackgroundColor;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
} |
public class CustomChipGroup : SfChipGroup
{
private static SelectedColorConverter colorConverter;
public CustomChipGroup() : base()
{
colorConverter = new SelectedColorConverter();
}
private void Child_ChildAdded(object sender, ElementEventArgs e)
{
var sfChip = e.Element as SfChip;
if (sfChip != null)
{
var dataContext = GetInternalProperty(typeof(SfChip), sfChip, "DataContext") as Word;
sfChip.SetBinding(SfChip.BackgroundColorProperty, new Binding()
{
Path = CheckMemberPath,
Source = dataContext,
Converter = colorConverter,
});
}
} |
private void Child_ChildAdded(object sender, ElementEventArgs e)
{
var sfChip = e.Element as SfChip;
if (sfChip != null)
{
. . .
if (dataContext.IsSelected)
SelectedItems.Add(dataContext);
}
} |