简体   繁体   中英

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. 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 . When I run my application, I get a Visible followed by a Collapsed no matter what. I even delay loaded my data with a timer and no Visible was triggered. Is there something that I am missing, or is this a bug where the Dependency Property is not triggering correctly?

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. 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. What if users had time-dependent values that would be used for each trigger?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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