wpfsolidcolorbrush

wpf net 4.5 System.Windows.Media.SolidColorBrush to System.Windows.Media.Brush


Strange question , does not affect operation .

Severity Count Data Context Binding Path Target Target Type Description File Line Project Error 8 SevenSegmentControl, Name='SevenSegmentUserControl' NumberColor Path.Fill, Name='top' Brush Cannot convert from type 'System.Windows.Media.SolidColorBrush' to 'System.Windows.Media.Brush'. Consider setting a converter on the binding.

https://www.codeproject.com/script/Articles/Download.aspx?file=/KB/WPF/319495/SevenSegmentSource.zip&rp=https://www.codeproject.com/


Solution

  • if you change to Mode=OneWay, no error msg. (you dont need to use the 2ways)

        <Style x:Key="PathStyle1" TargetType="{x:Type Path}">
            <Setter Property="Stretch" Value="Fill" />
            <Setter Property="Fill" Value="{Binding NumberColor, Mode=OneWay}"/>
        </Style>
        <Style x:Key="EllipseStyle1" TargetType="{x:Type Ellipse}">
            <Setter Property="Fill" Value="{Binding ColonColor, Mode=OneWay}"/>
            <Setter Property="StrokeThickness" Value="0"/>
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>