Vercas
Vercas

Reputation: 9141

Can't use bindings in this context?

So I have this code and I can't use the bindings!

        <ListView.View>
            <GridView>
                <GridViewColumn Header="File name">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <DockPanel>
                                <Image Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Left">
                                    <Image.Source>
                                        <MultiBinding Converter="{StaticResource fic}">
                                            <Binding Path="FileName" />
                                        </MultiBinding >
                                    </Image.Source>
                                </Image>
                                <TextBlock Margin="16,0,0,0">
                                    <Binding Path="FileName" />
                                </TextBlock>
                            </DockPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>

Long boring exception removed


                                <TextBlock Margin="16,0,0,0">
                                    <TextBlock.Text>
                                        <Binding Path="FileName" />
                                    </TextBlock.Text>
                                </TextBlock>

... Seems to work!

Upvotes: 0

Views: 280

Answers (2)

Stephen Chung
Stephen Chung

Reputation: 14605

Things inside <TextBlock> tags are items contained inside the text block, which can be a whole lot of spans and other text fragments.

If you need to bind the text in the text block, you need to bind to the Text property, as you've done in your question. It is a DependencyProperty that supports this binding.

The items inside the text block does not support direct binding, nor does it support directly putting binding objects in there. However, you may put in another control with a DependencyProperty that is a binding though.

Upvotes: 2

SLaks
SLaks

Reputation: 887225

You cannot bind the text of a textblock through its children.

Upvotes: 1

Related Questions