首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ScrollBarViewer的RepeatButton中使用背景图像不会显示图像

在ScrollBarViewer的RepeatButton中使用背景图像不会显示图像
EN

Stack Overflow用户
提问于 2013-03-19 04:05:00
回答 1查看 700关注 0票数 0

我正在尝试在WPF中创建自己的滚动查看器,它工作得很好,除了RepeatButton中的背景图像。如果我使用SolidColorBrush而不是ImageBrush,它工作得很好。下面是我的xaml,我已经验证了可以通过在滚动条中的其他地方添加ImageSource (特别是轨迹图像)来找到它。你知道为什么吗?forground Image显示正常。

代码语言:javascript
复制
<Style x:Key="ScrollBarButtonStyle" TargetType="RepeatButton">
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Width" Value="50"/>
    <Setter Property="Height" Value="50"/>        
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RepeatButton">
                <Grid Name="ButtonBackground">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ImageBrush ImageSource="{DynamicResource ListItemBackgroundBttnNormal}"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ImageBrush ImageSource ="{DynamicResource ListItemBackgroundBttnPressed}"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ImageBrush ImageSource = "{DynamicResource ListItemBackgroundBttnDisabled}"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" From="1.0" To="0.5"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ImageBrush ImageSource="{DynamicResource ListItemBackgroundBttnNormal}"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentPresenter
                          x:Name="contentPresenter"
                          Content="{TemplateBinding Content}"
                          ContentTemplate="{TemplateBinding ContentTemplate}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="{TemplateBinding Padding}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-19 16:46:48

尝试将DynamicResource更改为StaticResource,看看它是否仍然有效。如果找不到路径,DynamicResource不会显示任何错误,而StaticResource会执行tihs。我假设您的图像来源在这种情况下是未知的。确保您在<ResourceDictionary.MergedDictionaries>的App.xaml中添加了资源。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15485876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档