Panel.Background
속성이 System.Windows.Media.Brush
유형이 아니고 System.Windows.Media.Color
이 아니므로 SolidColorBrush
으로 변환해야합니다. 당신은 모두의 시나리오를 찾을 수 아래 :
설정은 System.Windows.Media.Color
유형
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{Binding Source={x:Static props:Settings.Default}, Path=Bkg}"/>
</Setter.Value>
</Setter>
설정이 System.Drawing.Color
유형이다이다 :이 당신은 SolidColorBrush
로 변환하는 사용자 정의 IValueConverter
필요합니다
public class ColorToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var dc = (System.Drawing.Color)value;
return new SolidColorBrush(new Color { A = dc.A, R = dc.R, G = dc.G, B = dc.B });
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
리소스에 정의한
:
(210)
<Window.Resources>
<local:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
</Window.Resources>
당신은 다음과 같이 사용할 수 있습니다 :
<Setter Property="Background" Value="{Binding Source={x:Static props:Settings.Default}, Path=Bkg, Converter={StaticResource ColorToBrushConverter}}"/>
왜 단순히'System.Windows.Media.Color' 유형의 설정을 만들? 설정 유형 콤보 상자에서'찾아보기 ... '를 클릭하고 PresentationCore -> System.Windows.Media -> Color를 선택하십시오. – Clemens
흠, 좋은. 그러나 투명 색상을 정의하는 방법은 무엇입니까? –
@PatrikPolakovic 어떤 문제라도 문제를 해결하면 바로 표시 할 수 있습니다. – loop