我一直在编写一个 WPF 程序,它使用自定义控件AnimatedScrollViewer
,继承自ScrollViewer
. 它具有以下默认模板:
<Style TargetType="{x:Type Controls:AnimatedScrollViewer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:AnimatedScrollViewer}">
<Grid x:Name="PART_LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ScrollBar x:Name="PART_HorizontalScrollBar"
Orientation="Horizontal"
IsEnabled="{TemplateBinding IsPaused}"
Value="{TemplateBinding HorizontalOffset}"
Maximum="{TemplateBinding ScrollableWidth}"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
<StackPanel Grid.Column="1">
<Image Source="{StaticResource LockedImage}"
Visibility="{TemplateBinding IsPlaying, Converter={StaticResource boolToVisConverter}}"/>
<Image Source="{StaticResource UnlockedImage}"
Visibility="{TemplateBinding IsPaused, Converter={StaticResource boolToVisConverter}}"/>
</StackPanel>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我将其设置为默认样式,使用:
[...]
public class AnimatedScrollViewer : ScrollViewer
{
static AnimatedScrollViewer()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AnimatedScrollViewer), new FrameworkPropertyMetadata(typeof(AnimatedScrollViewer)));
}
[...]
该样式在以下Generic.xaml
字典中被引用,而该字典又被引用为MergedDictionary
in App.xaml
:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ConvertersDictionary.xaml" />
<ResourceDictionary Source="pack://application:,,,/JamesWright.Utils.EndpointCaller.Views;component/Themes/EndpointStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/JamesWright.Utils.EndpointCaller.Views;component/Themes/ImageResources.xaml" />
<ResourceDictionary Source="pack://application:,,,/JamesWright.Utils.EndpointCaller.Views;component/Themes/Resources.xaml" />
<ResourceDictionary Source="pack://application:,,,/JamesWright.Utils.EndpointCaller.Views;component/Controls/AnimatedScrollViewer.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
真正奇怪的是,该样式仅在程序运行在我自己的机器和Windows 8.1 虚拟机上时应用于控件,而在我同事的计算机和团队机器上没有应用。我知道该样式未应用,因为ScrollBar
仅当“IsPaused”为真时才应启用关联。但是,在我同事的机器上,它始终处于启用状态。此外,我在模板中指定的图像不会作为结果出现。
是否有任何已知原因Style
无法在某些机器上应用 a?我已经反编译了应用程序,并且资源引用了正确的文件。感谢任何帮助,因为我们整天都在拔头发:P
更新:我已将其下载到我的 Windows 8 笔记本电脑上,并且该样式已正确应用。
更新#2:我尝试使用相对路径而不是pack
语法,但没有成功