简体   繁体   English

如果使用绑定/转换器,则ComputedVerticalScrollBarVisibility触发器不起作用

[英]ComputedVerticalScrollBarVisibility Trigger does not work if using binding/converter

This question is very correlated to another SO question of mine , but this one is even more specific. 这个问题与我的另一个SO问题非常相关,但是这个问题更加具体。 Feel free to head to the other question for more details, but I should provide everything you need here. 随时询问其他问题以获取更多详细信息,但是我应该在此处提供您所需的一切。

I have implemented a custom style to my listview so that I could gain access to the scrollbar properties using the following (I removed some of the misc that isnt pertinent) 我已经为列表视图实现了自定义样式,以便可以使用以下内容访问滚动条属性(我删除了一些不相关的杂项)

<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="ScrollViewer">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ScrollViewer">
                <Grid Background="{TemplateBinding Background}">
                    <DockPanel Margin="{TemplateBinding Padding}">
                        <ScrollViewer DockPanel.Dock="Top" Focusable="false">   
                    </DockPanel>
                    <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal"  Grid.Row="1" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Value="{TemplateBinding HorizontalOffset}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    <ScrollBar Name="PART_VerticalScrollBar" Grid.Column="1" Margin="20,0" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="ComputedVerticalScrollBarVisibility" Value="Collapsed">
                        <Setter Property="Width">
                            <Setter.Value>
                                <Binding  
                                    ConverterParameter="400" 
                                    RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type ListView}}"
                             >
                                    <Binding.Converter>
                                        <Converters:ListViewColumnResizeConverter/>
                                    </Binding.Converter>
                                </Binding>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="ComputedVerticalScrollBarVisibility" Value="Visible">
                        <Setter Property="Width">
                            <Setter.Value>
                                <Binding  
                                    ConverterParameter="500" 
                                    RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type ListView}}"
                             >
                                    <Binding.Converter>
                                        <Converters:ListViewColumnResizeConverter/>
                                    </Binding.Converter>
                                </Binding>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Notice the two triggers that I have, one for Visible and one for Collapsed . 请注意,我有两个触发器,一个是Visible ,另一个是Collapsed When I run my application, I get a Visible followed by a Collapsed no matter what. 当我运行我的应用程序时,无论如何,我都会Visible和“ Collapsed I even delay loaded my data with a timer and no Visible was triggered. 我什至延迟了使用计时器加载数据的时间,并且未触发任何Visible Is there something that I am missing, or is this a bug where the Dependency Property is not triggering correctly? 是否有我缺少的东西,或者这是Dependency Property未正确触发的错误?

UPDATE UPDATE

So, I noticed that a barebones version of this was working (not using the binding and converter), so I removed that from my code and made the triggers simply update the background color. 因此,我注意到该系统的准系统正在运行(不使用绑定和转换器),因此我从代码中删除了该系统,并使触发器简单地更新了背景色。 And, it works, so why does adding a binding/converter mess up the trigger? 而且,它起作用了,那么为什么添加绑定/转换器会使触发器混乱呢?

Well, the answer definitely does not help me, but it appears that the values from the binding are cached. 好吧,答案肯定对我没有帮助,但是似乎绑定中的值已被缓存。 Since my codebehind converter was more of a hack to gain code access to the Computed trigger I was not even using the return values. 由于我的代码隐藏转换器更像是一种获取对Computed触发器的代码访问权限的工具,所以我什至没有使用返回值。 But, I went ahead and tied unique color values to each trigger and as soon as the scrollbar became visible, my code was not hit again, but the return value from the initial call was used. 但是,我继续将唯一的颜色值绑定到每个触发器,并且一旦滚动条变得可见,我的代码就不再被击中,而是使用了初始调用的返回值。 I must admit that this is quite clever on the MS team, but is a stumbling block for me. 我必须承认,这在MS团队中相当聪明,但对我来说却是一个绊脚石。 What if users had time-dependent values that would be used for each trigger? 如果用户具有将用于每个触发器的时间相关值怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM