开发者

Is it possible to bind to a control's property from a datatemplate?

Ok, sounds odd, and there's likely a better way, but I haven't seen it yet.

What I'm trying to do is restyle a ListPicker under Windows Phone 7.

What I need is to

  1. get rid of the header (that's easy, just define a null ListPicker.HeaderTemplate).
  2. Force the picker to always go to full mode when clicked (again, easy, just set the ItemCountThreshold to 1).
  3. Restyle the itemtemplate used when in FullMode (again, easy, just define a FullModeItemTemplate)
  4. Incorporate the ListPicker's "HEADER" property value into the ItemTemplate (since only one item will ever show, i need the header text "embedded" within the one item).

It's that number 4 that I can't seem to get.

I've defined a listpicker like so (i'm directly defining the templates inline instead of in resources for now, just to keep things simple).

        <phonekit:ListPicker Header="Header Text" x:Name="ListOfSounds" 
                             SelectedItem="{Binding Path=DepartureChime, Mode=TwoWay, Converter={StaticResource EnumDescriptionToStringConverter}}"  
                             ItemCountTh开发者_运维知识库reshold="1">
            <phonekit:ListPicker.ItemTemplate>
                <DataTemplate>
                     <StackPanel Orientation="Horizontal" Background="Transparent">
                         <TextBlock Text="{TemplateBinding Header}" />
                         <TextBlock Text="{Binding}" />
                         <TextBlock Text=">" />
                     </StackPanel>
                </DataTemplate>
            </phonekit:ListPicker.ItemTemplate>

Ignoring all the obvious formatting bits for now, the problem I'm having is that I can't use {TemplateBinding Header} from within a datatemplate. I've used it from a ControlTemplate no problem.

The result of this ItemTemplate should be an item displayed such as

 {TextOfHeader}{Content of selected Item}>

I'm just not sure how to go about getting at a property of the templated control (the listpicker in this case).

Any ideas?


Take advantages of RelativeSource:

<TextBlock Text="{Binding Path=Header, RelativeSource={RelativeSource AncestorType={x:Type phonekit:ListPicker}}}" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜