Wpf 刷新在样式中使用值转换器的绑定
我在项目中使用Telerik RadTimeline控件,我有一个TimelineItemTemplate模板:Wpf 刷新在样式中使用值转换器的绑定,wpf,binding,telerik,ivalueconverter,valueconverter,Wpf,Binding,Telerik,Ivalueconverter,Valueconverter,我在项目中使用Telerik RadTimeline控件,我有一个TimelineItemTemplate模板: <telerik:RadTimeline x:Name="myTimeline" PeriodStart="{Binding PeriodStart}" PeriodEnd="{Binding PeriodEnd}"
<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>
opdSettings是ObjectDataProvider:
<ObjectDataProvider x:Key="odpSettings" ObjectType="{x:Type src:AppSettings}"/>
加载应用程序时,控件会正确显示,但当应用程序运行时,我需要更改odpSettings的一些属性,这些属性会影响时间线布局,但不会显示新值
是否有方法刷新转换器绑定,以便控件显示更改?我尝试使用UpdateSourceTrigger=PropertyChanged,但没有成功
还是有其他方法可以实现我的目标
提前谢谢
Alberto我认为这是因为您在绑定中使用了Source=StaticResource,所以WPF假定该值是静态的,并且永远不会更改。您可以改为将其更改为DynamicSource,并确保它实现INotifyPropertyChanged吗?我已经在使用INotifyPropertyChanged,我尝试更改为DynamicSource,但出现了下一个错误:无法在类型绑定的源属性上设置DynamicResourceExtension。只能对DependencyObject的DependencyProperty设置DynamicResourceExtension。
<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;
}
<ObjectDataProvider x:Key="odpSettings" ObjectType="{x:Type src:AppSettings}"/>