开发者

Why does this work? (Binding in a Panorama-Template, Windows Phone 7)

开发者 https://www.devze.com 2023-02-03 03:05 出处:网络
The following code does work, but I don\'t understand exactly why. I just got to that solution by fluke.

The following code does work, but I don't understand exactly why. I just got to that solution by fluke.

<controls:Panorama x:Name="PanoramaMama" Title="my header">
    <controls:Panorama.TitleTemplate>
        <DataTemplate>
            <TextBlock Foreground="Red" Text="{Binding}"/>
        </DataTemplate>
    </controls:Panorama.TitleTemplate>
    <controls:Panorama.HeaderTemplate>
        <DataTemplate>
            <TextBlock Foreground="Blue" Text="{Binding}" />
        </DataTemplate>
    </controls:Panorama.HeaderTemplate>

    <!--Panorama item one-->
    <controls:PanoramaItem Header="item one"&g开发者_StackOverflow社区t;

        <Grid/>
    </controls:PanoramaItem>

    <!--Panorama item two-->
    <controls:PanoramaItem Header="item two">
        <Grid/>
    </controls:PanoramaItem>
</controls:Panorama>

What I wanted to achieve was to create one HeaderTemplate for all PanoramaItems and specify the header-text in each PanoramaItem. e.g.: <controls:PanoramaItem Header="item one">

In the template, the binding without any parameters does the job: Text="{Binding}"

Why is this working? The binding must use some default values (default Path or so) - which are those default values? What would the non abbreviated version of the binding be?


You've assigned a string as the object to use for the Header content.

You've also specified a DataTemplate to present the object assigned to the Header property. In this case as stated above that object is simply a string. This string therefore becomes the DataContext of the ContentPresenter ultimately used to present the header.

When you use {Binding} without any Path the binding will return the source object. Without specifying any source object the default source object is the current DataContext for the element on which the binding is set. Therefore the result of {Binding} in this case is the string you assigned to the Header property.

There is no "non abbreviated version" for this binding, certainly not one that makes any sense.

0

精彩评论

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