刷新在样式中使用值转换器的绑定

时间:2014-08-14 18:39:24

标签: wpf binding telerik ivalueconverter valueconverter

我在项目中使用Telerik RadTimeline控件,我有一个TimelineItemTemplate的模板:

<telerik:RadTimeline x:Name="myTimeline" 
                             PeriodStart="{Binding PeriodStart}"
                             PeriodEnd="{Binding PeriodEnd}"
                             VisiblePeriodStart="{Binding VisiblePeriodStart, Mode=TwoWay}"
                             VisiblePeriodEnd="{Binding VisiblePeriodEnd, Mode=TwoWay}"
                             StartPath="StartDate"
                             DurationPath="Duration"        
                             GroupPath="Title"
                             GroupExpandMode="Multiple"
                             ItemsSource="{Binding myData}"
                             TimelineItemTemplate="{StaticResource myTemplate}"
                             ScrollMode="ScrollOnly" 
                             IsSelectionEnabled="True" SelectionMode="Extended"
                             DataContext="{Binding ElementName=vm}">
</telerik:RadTimeline>

我的模板是下一个:

<DataTemplate x:Key="myTemplate">
    <controls:CustomTimelineControl Style="{StaticResource myStyle}"/>
</DataTemplate>

我的风格:

<Style x:Key="myStyle" TargetType="controls:CustomTimelineControl">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="controls:CustomTimelineControl">
            <Border Height="{Binding Source={StaticResource odpSettings}, UpdateSourceTrigger=, Converter={StaticResource visibleToHeightConverter3}, ConverterParameter=Largos}" Margin="{Binding Source={StaticResource odpSettings},Path=ItemBorderMargin,Mode=OneWay}">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="largosHeatItem" Storyboard.TargetProperty="Background" Duration="0.00:00:00.05">
                                    <DiscreteObjectKeyFrame KeyTime="0.00:00:00.0" Value="{StaticResource HeatItem_Background_MouseOver}" />
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="largosHeatItem" Storyboard.TargetProperty="Background" Duration="0.00:00:00.05">
                                    <DiscreteObjectKeyFrame KeyTime="0.00:00:00.0" Value="{StaticResource HeatItem_Background_MouseOver}" />
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>

                <Border x:Name="largosHeatItem" Height="{Binding Source={StaticResource odpSettings}, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource visibleToHeightConverter2}, ConverterParameter=Largos}"
                    Margin="0, 0, 0, 0" Background="{Binding DataItem.Status, Converter={StaticResource typeToColorConverter}}">
                    <TextBlock Text="{Binding DataItem.HeatId}"
                        FontFamily="Segoe UI" 
                        Foreground="{StaticResource HeatItem_Foreground}"
                        FontSize="{Binding Source={StaticResource odpSettings}, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource visibleToFontSizeConverter}}"
                        Height="{Binding Source={StaticResource odpSettings}, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource visibleToHeightConverter1}, ConverterParameter=Largos}"
                        TextAlignment="Center"/>
                </Border>
            </Border>
        </ControlTemplate>
    </Setter.Value>
</Setter>

我有边框高度,文本块大小和高度的转换器,作为值我发送一个包含多个属性的对象,以便设置正确的值,例如:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        AppSettings objSettings = value as AppSettings;
        double val = 0;

        if (parameter != null && parameter is string)
        {
            switch((string)parameter)
            {
                case "Planos":
                    if(objSettings.BothGantt)
                        val= objSettings.PlanosItemHeight1;
                    else
                        val= objSettings.PlanosItemHeightMax1;
                    break;
                case "Largos":
                     if(objSettings.BothGantt)
                        val= objSettings.LargosItemHeight1;
                    else
                        val= objSettings.LargosItemHeightMax1;

                    break;
            }
        }

        return val;
    }

opdSettings是一个ObjectDataProvider:

<ObjectDataProvider x:Key="odpSettings" ObjectType="{x:Type src:AppSettings}"/>

加载应用程序时,控件显示正确,但是当应用程序运行时,我需要更改影响时间轴布局但不显示新值的odpSettings的某些属性。

有没有办法“刷新”转换器绑定,以便控件显示更改?我尝试使用UpdateSourceTrigger = PropertyChanged但它没有用。

还是有另一种方法来实现我的目标吗?

提前致谢。

阿尔贝托

0 个答案:

没有答案