ユーザーが独自の XAML の一部としてグラデーションの停止色を設定することを意味していると思いますか? その場合は、 a を使用しDependencyProperty
て をそれにバインドできますGradientStop.Color
。
UserControl.cs で:
public CoolControl()
{
InitalizeComponent();
SetValue(ColorProperty, Colors.Red); // or any default color
}
public static DependencyProperty ColorProperty = DependencyProperty.Register("BackgroundColor", typeof(Color), typeof(CoolControl)); // replace CoolControl with the name of your UserControl
public Color BackgroundColor
{
get
{
return (Color)GetValue(ColorProperty);
}
set
{
SetValue(ColorProperty, value);
}
}
UserControl.xaml で:
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{Binding BackgroundColor, RelativeSource={RelativeSource AncestorType={x:Type my:CoolControl}}}" Offset="1" /> <!-- replace my:CoolControl with your namespace declaration and UserControl name -->
<GradientStop Color="Black" Offset="0" />
</LinearGradientBrush>
コントロールの使用:
<Grid>
<my:CoolControl BackgroundColor="Blue" />
</Grid>