WPF Fuckery


  • Dupa

    This is driving me nuts.

    At work we're using DevExpress. I need to paint a grid with custom cell templates. I got all that.

    What stumped me today was this piece of code:

    <MyCell>
        <MyCell.Text>
            <Binding Path="Column.FieldName" />
        </MyCell.Text>
    </MyCell>
    

    This correctly put value of Column.FieldName into the cell.

    However, when I switched to using a multi-value converter, it all broke suddenly:

    <MyCell>
        <MyCell.Text>
            <MultiBinding Converter="{StaticResource DupaConverter}">
               <Binding Path="Row.RowData.Model" />
               <Binding Path="Column.FieldName" />
            </MultiBinding>
        </MyCell.Text>
    </MyCell>
    

    With this setup, the value of the Model was always there, but FieldName was always an empty string (default value of FieldName).

    It seems that converters are evaluated at a different point in time, sometime when the Column.FieldName is not yet or no longer there.

    Do you have any insight?


  • Dupa

    For closure: I ended up modifying my control and I simply bound both those fields to MyCell's dependency properties. Then I use a delegate to correctly bind Text.



  • If this is someone's custom control, they may have managed to break it badly enough that doing obvious things doesn't work right. Your current solution might just be the best you can do. Usually control libraries are really bad about letting you use them except in the narrow scope the authors preferred.


  • Dupa

    @magus said in WPF Fuckery:

    If this is someone's custom control, they may have managed to break it badly enough that doing obvious things doesn't work right.

    You mean the one that I want to bind Column.FieldName from? It's DevExpress, maybe I should ask on their support boards?...



  • @kt_ Maybe? I mean I'm confused looking at your code, because of the mixed binding syntax. I haven't used a multi value converter in a while, but I didn't think just a static binding to the converter was enough; I thought you had to mess with parameters. A multbinding with a multiconverter breaks my mind. Normally I'd just bind the parameters in the multi converter and not have a multibinding at all, I think.

    But it's been a while, too...


  • Dupa

    @magus said in WPF Fuckery:

    @kt_ Maybe? I mean I'm confused looking at your code, because of the mixed binding syntax. I haven't used a multi value converter in a while, but I didn't think just a static binding to the converter was enough; I thought you had to mess with parameters. A multbinding with a multiconverter breaks my mind. Normally I'd just bind the parameters in the multi converter and not have a multibinding at all, I think.

    But it's been a while, too...

    Indeed it has. You need to use a multi binding with multi converter. You can only pass a value and a parameter to a value converter.

    What I posted is a standard syntax for this kind of thing.


  • Banned

    @kt_ said in WPF Fuckery:

    DupaConverter

    👍🏻


  • Banned

    As of your question - why not make the viewmodel expose the property in the exact format you need so you don't need to use any converters?


  • Dupa

    @gąska said in WPF Fuckery:

    As of your question - why not make the viewmodel expose the property in the exact format you need so you don't need to use any converters?

    Because I'm dynamically generating a grid and I need to paint each cell. So on a column I put the information which field imma bind to and then in cell I need to actually bind to that field.

    DevExpress supports automatic binding to a property of a model, but you have to let it paint the cell.


  • Dupa

    @gąska said in WPF Fuckery:

    @kt_ said in WPF Fuckery:

    DupaConverter

    👍🏻

    I actually committed a class called exactly that yesterday, by a mistake.

    For non-Polish speakers: this means AssConverter.


  • Banned

    @kt_ is it possible for you to change the format of column's properties, or add new ones? Then you could do what I said, but on column instead of property.

    Also - does it work with single-value converter?


  • Dupa

    @gąska said in WPF Fuckery:

    @kt_ is it possible for you to change the format of column's properties, or add new ones? Then you could do what I said, but on column instead of property.

    Um, I don't really understand what you mean.

    That being said, I doubt it. I'd have to subclass the column and then I'd have to subclass the grid and god knows how much would break, plus it would be a huge PITA when upgrading to a newer version of DX.

    Also - does it work with single-value converter?

    I thought about it but I didn't try it. I was pressed for time, so I went the dependency property route.