如何在GanttControl中绑定LinearGradientBrush?

时间:2016-11-18 08:50:58

标签: c# wpf xaml wpf-controls silverlight-5.0

我有一个GanttControlTaskItemTemplate包含GridRectangle,负责执行任务。 Rectangle的属性为FillStroke。这些属性是从StaticResource s设置的,其中定义了任务的颜色。我尝试将LinearGradientBrush绑定到我的模型的属性Color

有我的Xaml代码:

<LinearGradientBrush x:Key="ParentBarFill" StartPoint="0,0" EndPoint="0,1">
    <LinearGradientBrush.GradientStops>
        <GradientStop Color="Black" Offset="0" />
        <GradientStop Color="White" Offset="0.1" />
        <GradientStop Color="Gray" Offset="0.2" />
        <GradientStop Color="Black" Offset="0.6" />
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>

                                           ** /&gt;            

<SolidColorBrush x:Key="TaskItemBarStroke" Color="{Binding Color}"/>  **<!--There is the Problem too-->**

    <!-- Task look and feel styles -->
    <!--Transparent-->
    <Style TargetType="Thumb" x:Name="TransparentThumb" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Thumb">
                    <Grid>
                        <Border CornerRadius="2" Background="Transparent" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<flexyGantt:FlexyGantt x:Name="fxgantt" Grid.Row="1" Grid.Column="0" ItemTemplate="{StaticResource TreeTemplate}"
                        TaskListBinding="{Binding EngineersInterval}" TaskStartTimeBinding="{Binding StartInteval, Mode=TwoWay}"
                        TaskEndTimeBinding="{Binding FinishInterval, Mode=TwoWay}" ParentTaskStartTimeBinding="{Binding OverallStartTime}"
                        ParentTaskEndTimeBinding="{Binding OverallEndTime}"
                        TreeHeaderContent="Teams" CustomSourceListViewTemplate="{StaticResource flexyGanttTableTemplate}"
                        OverlappedTasksRenderingOptimization="ShrinkHeight"  RowHeight="25" TaskTimeChanged="Fxgantt_OnTaskTimeChanged" 
                        >
    <flexyGantt:FlexyGantt.TaskItemTemplate>
        <DataTemplate>
            <Grid ToolTipService.ToolTip="{Binding ToolTipText}">
                <Rectangle x:Name="taskBar" HorizontalAlignment="Stretch" 
                               Fill="{StaticResource TaskItemBarFill}" Stroke="{StaticResource TaskItemBarStroke}"
                                   StrokeThickness="1" RadiusX="4" RadiusY="4"/>
                            <!--Include a thumb with name "dragThumb" to enable drag-moving the task functionality.
                     ZIndex=2 ensures this is drawn above the Rectangle-->
                            <Thumb x:Name="dragThumb" Canvas.ZIndex="2" Style="{StaticResource TransparentThumb}"  />
                            <!--Include a thumb with name "resizeThumb" to enable resizing the task functionality 
                     ZIndex=3 ensures this is drawn above the dragThumb-->
                            <Thumb x:Name="resizeThumb" Canvas.ZIndex="4" HorizontalAlignment="Right" Cursor="SizeWE"  
                           Style="{StaticResource TransparentThumb}" Width="3" />
                            <!--Include a thumb with name "resizeStartThumb" to enable resizing to the left (changing starttime) functionality 
                     ZIndex=3 ensures this is drawn above the dragThumb-->
                            <Thumb x:Name="resizeStartThumb" Canvas.ZIndex="3" HorizontalAlignment="Left" Cursor="SizeWE"  
                           Style="{StaticResource TransparentThumb}" Width="3" Height="14"/>
            </Grid>
        </DataTemplate>
    </flexyGantt:FlexyGantt.TaskItemTemplate>
</flexyGantt:FlexyGantt>

我该怎么绑这个?我也是模特:

public class GanttIntervalModel : INotifyPropertyChanged
{
public Color Color
    {
        get { return _color; }
        set
        {
            if (Equals(value, _color)) return;
            _color = value;
            OnPropertyChanged(nameof(Color));
        }
    }

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

0 个答案:

没有答案