Is Avalonia.Media.Color bindable to an IBrush? #16269
Answered
by
stevemonaco
Shadowblitz16
asked this question in
Q&A
-
I was just wondering because the rider ide display is not updating when I try to bind it. public partial class SectionViewModel : ObservableObject
{
[ObservableProperty] private Rect _bounds = new Rect(0, 0, 256, 240);
[ObservableProperty] private Color _color = Colors.Black;
[ObservableProperty] private int _scale = 2;
[ObservableProperty] private Vector _cameraSize = new Vector(256, 240); <UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:v="using:AvaloniaMario.Views"
xmlns:vm="using:AvaloniaMario.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaMario.Views.SectionView"
x:DataType="vm:SectionViewModel">
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:SectionViewModel/>
</Design.DataContext>
<StackPanel>
<ScrollViewer>
<Canvas Width="32" Height="32" Background="{Binding Color}">
</Canvas>
</ScrollViewer>
</StackPanel>
</UserControl>
|
Beta Was this translation helpful? Give feedback.
Answered by
stevemonaco
Jul 9, 2024
Replies: 1 comment 1 reply
-
There's no implicit conversion and <Canvas Width="32" Height="32">
<Canvas.Background>
<SolidColorBrush Color="{Binding Color}" />
</Canvas.Background>
</Canvas> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Shadowblitz16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's no implicit conversion and
IBrush
itself doesn't support a color as it's a very general drawing object. You need to write a converter or use the full property setter syntax. eg.