1

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 trivial 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...)

Community
  • 1
  • 1
Stigma
  • 1,686
  • 13
  • 27
  • Where's your code? How are we to know if you are doing it right or wrong? – Jeff Mercado May 08 '11 at 18:35
  • See the first paragraph. As for doing it right/doing it wrong: the suggestions given there I implemented nearly to the letter, and I dare say they aren't quite rocket-science. I tried a lot of variations, the essential pieces of which I mentioned in the question as well, but what would you have me do beyond that? Recreate every single variety I remember trying? :) – Stigma May 08 '11 at 19:48
  • Ah sorry about that. When I see "I tried to do this but it doesn't work," I would expect to see code to go along with it. Unfortunately that happens way too often here and is difficult to offer any good advice. – Jeff Mercado May 08 '11 at 21:56
  • @Jeff Mercado: Not a problem. I run into the issue of inexperienced programmers asking questions without doing any investigation or debugging themselves far too often. They cause people to think summarized problems or a lack of code constitutes a lack of effort and/or intelligence - while in reality, it is just someone cutting to the chase to save everyone a bit of time. By now, the question is already answered, but thank you for commenting anyway, Jeff. I appreciate it. :) – Stigma May 09 '11 at 05:46

1 Answers1

1

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>
H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Ah, so ItemContainerStyle is the piece of the puzzle that I was missing! I'll try it out after I am done watching my movies. :) However, I want to ask - would this not apply to _all_ elements I might put into that column, not just the ProgressBar? I take it I would need a seperate bunch of DataTriggers for the ItemContainerStyle? – Stigma May 08 '11 at 19:25
  • It does not affect the other columns from what i've seen. At least text is still left aligned (possibly even if the TextBlock now stretches the whole width) – H.B. May 08 '11 at 20:26
  • Consider it pre-emptive worrying on my part. :) I'll consider it answered as it does exactly what I'm asking for, thank you! (Off to the next weird problem that I might be able to ignore.) – Stigma May 08 '11 at 20:30