ContentProperty and DataContext.
Posted: 02 Sep 2022, 02:23
I have a custom control like this:
And I have a framework object like this:
And I set tiers like this:
How do I see the Tiers to the TieredProgressBar's DataContext? I tried doing this:
Code: Select all
[ContentProperty("Tiers")]
public class TieredProgressBar : Control
{
public static readonly DependencyProperty TiersProperty = DependencyProperty.Register("Tiers", typeof(ObservableCollection<Tier>), typeof(TieredProgressBar));
public ObservableCollection<Tier> Tiers
{
get => (ObservableCollection<Tier>)GetValue(TiersProperty);
set => SetValue(TiersProperty, value);
}
}Code: Select all
public class Tier : FrameworkElement
{
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(float), typeof(Tier));
public float Value
{
get => (float)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
}Code: Select all
<TieredProgressBar Maximum="10">
<salt:Tier Value="{Binding TotalValue}" />
<salt:Tier Value="2" />
<TieredProgressBar>but the Value bindings still fail. Is there a way to have them set automatically to the TieredProgressBar? Thanks!tier.DataContext = DataContext;