开发者

Make ProgressBar take available space

开发者 https://www.devze.com 2023-03-03 14:53 出处:网络
This question directly relates to (the accepted answer of) this question: Change ListView CellTemplate based on state of item, which holds all the relevant XAML in the accepted answer.

This question directly relates to (the accepted answer of) this question: Change ListView CellTemplate based on state of item, which holds all the relevant XAML in the accepted answer.

One of these states requires a ProgressBar. Which works, except for the fact I can't get it to look and act the way I want it to, which is to take all available horizon and vertical space without taking more space than required.

In an attempt to solve this, I have tried to follow the suggestions given here, but nothing I do seems to have a single effect. The XxxContentAlignment options go ignored, no matter whether I apply them to ContentControls, ListViewItems or whatever else I came up with along the way. The Binding to the named element also fails, giving me a

Cannot find source for binding with reference

error which refers to its inability to find what the other answer calls col1. All other suggestions I have found are variations of these, either involving ActualWidth or its ActualHeight cousin, or stuff involving RelativeSource and FindAncestor.

At this point of trying to fix this rather trivia开发者_JAVA技巧l thing for the last 2 hours, I think I can really use the final nudge to show me in the right direction. (And probably point out the obvious mistakes I've been making...)


This is at a high level, i for one got it to stretch via changing the ItemStyle:

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListView.ItemContainerStyle>

Some code i tested it on, just so you see that no HorizontalAlignment or HorizontalContentAlignment was set:

<GridViewColumn Header="Status">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <ContentControl>
                <ContentControl.Style>
                    <Style TargetType="{x:Type ContentControl}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsActive}" Value="True">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <StackPanel>
                                                <ProgressBar Height="20"
                                                             Value="{Binding Id}" Minimum="0" Maximum="10"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>

                            <!-- ... -->
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>
0

精彩评论

暂无评论...
验证码 换一张
取 消