I have an ItemsControl element that populates a Stackpanel. Its bound to a ObservableCollections full of "LedModel" objects (see below).
I cannot get the binding for Brush, Size and BlurRadius to work.
Oddly enough however the binding for the Label does work...
<ItemsControl
ItemsSource="{Binding ElementName=Control, Path=Leds}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical"
IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Ellipse
Width="{Binding Size}"
Height="{Binding Size}"
Fill="{Binding Brush}">
<Ellipse.Effect>
<BlurEffect
Radius="{Binding BlurRadius}" />
</Ellipse.Effect>
</Ellipse>
<Label Content="{Binding ColorString}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
public partial class LEDStack : UserControl, INotifyPropertyChanged {
// ...
public ObservableCollection<LEDModel> Leds { get; }
// ...
}
public class LEDModel {
public string ColorString => GetColorString();
public SolidColorBrush Brush { get; set; } = Brushes.Orange; //does not bind
public double Size { get; set; } = 25d; // does not bind
public double BlurRadius { get; set; } = 10d; // does not bind
private string GetColorString() {
return $"{Brush.Color.R}, {Brush.Color.G}, {Brush.Color.B}";
}
}
It does not throw me any error or warning in IDE, during compile or at runtime. My IDE also shows me the binding worked correctly and when inspecting the UI tree I see the stackpanel was properly populated (and I can see all the labels in my app)
Using Brush or Color instead of SolidColorBrush --> did not work
Using int or float for Size / BlurRadius --> did not work