开发者

bind the selected item template to another control template

开发者 https://www.devze.com 2023-04-05 20:51 出处:网络
I got a listbox with listing down item, each item is stackpanel with an icon and description text. <ListBox x:Name=\"lstSlectionTools\"

I got a listbox with listing down item, each item is stackpanel with an icon and description text.

<ListBox x:Name="lstSlectionTools"
         SelectedIndex="2"
         SelectionChanged="ListBox1_SelectionChanged">

    <StackPanel Orientation="Horizontal" >
      <ContentControl Template="{StaticResource Icon1}"/>
      <TextBlock Margin="3,0,0,0" Text="Item1" />
    </StackPanel>

    <StackPanel Orientation="Horizontal" >
      <ContentControl Template="{StaticResource Icon2}"/>
      <TextBlock Margin="3,0,0,0" Text="Item2" />
    </StackPanel>

    <StackPanel Orientation="Horizontal" >
      <Con开发者_如何转开发tentControl Template="{StaticResource Icon13}"/>
      <TextBlock Margin="3,0,0,0" Text="Item3" />     
    </StackPanel>

<StackPanel Orientation="Horizontal" >
      <ContentControl Template="{StaticResource Icon4}"/>
      <TextBlock Margin="3,0,0,0" Text="Item4" />
    </StackPanel>
</ListBox>

I want to show the selected item icon something like:

<ContentControl x:Name="selectTool"
                Template="{Binding SelectedItem.Template, ElementName=lstSlectionTools}"" />

I am unable to figure out how to bind selected item (i.e. stackpanel first child's template to the selectTool's template.


The Binding.Path in this case would be SelectedItem.Children[0].Template.

0

精彩评论

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