开发者

GradientStop Color Binding on DependencyProperty

开发者 https://www.devze.com 2022-12-22 07:12 出处:网络
Below, I Have these Resourcei want to make binding on the thi开发者_如何学编程rd GradientStop to MyColor ,MyColor is DependencyProperty but in not working if i remove binding and put static Color \"#f

Below, I Have these Resource i want to make binding on the thi开发者_如何学编程rd GradientStop to MyColor ,MyColor is DependencyProperty but in not working if i remove binding and put static Color "#ff000000" it is Working can some body help me???

 <Grid.Resources>
            <LinearGradientBrush x:Key="MyBrush" EndPoint="0, 1" StartPoint="0, 0">
                <GradientStop Color="#00000000" Offset="1"/>
                <GradientStop Color="#FFFFFFFF" Offset="1"/>
                <GradientStop Color="{Binding Path=MyColor}" Offset="0"/>
                <!--#ff000000 -->

            </LinearGradientBrush>

            <Style x:Key="ThumbStyle" TargetType="{x:Type Thumb}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate >
                            <Rectangle StrokeThickness="1" StrokeDashCap="Round" 
                                       Stretch="Fill" Name="ThumbContnet" Fill="{StaticResource MyBrush}"></Rectangle>
                            <!---->
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

Regards Fadi AL Sayyed


According to your comments, you haven't set DataContext itself. Declaring a dependency property isn't enough to make bindings work. In the user control's constructor write:

public class MyControl : UserControl
{
  public static readonly DependencyProperty MyColorProperty = DependencyProperty.Register("MyColor", typeof(Color), typeof(StageToolsWindow), new FrameworkPropertyMetadata((Color)Colors.Black));

  public Color MyColor 
  {
    get { return (Color)GetValue(MyColorProperty); } 
    set { SetValue(MyColorProperty, value); } 
  }

  public MyControl()
  {
    InitializeComponent();
    DataContext = this;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消