2016-10-30 3 views
1

リストボックスのエントリのヒントを表示したいとします。 ツールキットには、テキストボックスと、リストボックスのエントリにイメージのコピー(大きい方)が含まれます テキストボックスにテキストを表示するか、表示するイメージを取得できます。 画像を表示するが、テキストがc#wpfバインディングがdatacontextsで動作しない

<ControlTemplate TargetType="{x:Type ListBoxItem}"> 
        <Border x:Name="Bd" SnapsToDevicePixels="true" Background="#EEFFFFFF" BorderBrush="#FFCCCCCC" 
          HorizontalAlignment="Center" VerticalAlignment="Center" 
          BorderThickness="1"> 
         <Grid> 
          <StackPanel Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left">          
           <Image x:Name="img" ToolTipService.Placement="Top" 
             Source="{Binding Path=ImageUri}" Height="64" Stretch="Uniform" Width="64"> 
            <Image.RenderTransform> 
             <TransformGroup> 
              <ScaleTransform ScaleX="1" ScaleY="1" x:Name="scaleTrans"/> 
             </TransformGroup> 
            </Image.RenderTransform> 
            <Image.ToolTip> 
             <ToolTip BorderBrush="{x:Null}" Background="{x:Null}" Effect="{x:Null}" 
               DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}" 
               HasDropShadow="False"> 
              <Border Background="{x:Null}" VerticalAlignment="Center" Margin="0" Width="600" 
                HorizontalAlignment="Center"> 
               <Grid Background="{x:Null}"> 
                <StackPanel > 
                <TextBlock Margin="5" Padding="5" FontSize="14" FontWeight="Bold" 
                   Text="{Binding Path=FTitle}" 
                   Background="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}"/> 
                <Border Margin="8,0,8,12.5" VerticalAlignment="top"> 
                  <Image Source="{Binding Path=Source}"/> 
                </Border> 
                </StackPanel> 
               </Grid> 
              </Border> 
             </ToolTip> 
            </Image.ToolTip> 
           </Image> 
          </StackPanel> 
         </Grid> 
        </Border> 
       </ControlTemplate> 

このコードされていないコードがツールチップでリストボックス によって以下のコードを使用するためのコード(ディスプレイ上のリストのように画像の一部であるが、いないテキストボックス

<ToolTip BorderBrush="{x:Null}" Background="{x:Null}" Effect="{x:Null}" 
    DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}" 
    HasDropShadow="False"> 
      <Border Background="{x:Null}" VerticalAlignment="Center"Margin="0" Width="600" 
                HorizontalAlignment="Center"> 
       <Grid Background="{x:Null}"> 
        <StackPanel > 
         <TextBlock Margin="5" Padding="5" FontSize="14" FontWeight="Bold" 
                   Text="{Binding Path=FTitle}" 
                   Background="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}"/> 
        <Border Margin="8,0,8,12.5" VerticalAlignment="top"> 
          <Image Source="{Binding Path=Source}"/> 
        </Border> 
        </StackPanel> 
       </Grid> 
       </Border> 
      </ToolTip> 

あなたは

DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}" from <ToolTip 

を削除する場合、期待どおりテキストが動作しますが、画像が今失敗(予想通り)0 I a)はFTitleエントリ観察コレクションへのTextBlock結合点は、リストボックスの項目

<TextBlock Margin="5" Padding="5" FontSize="14" FontWeight="Bold" 
     Text="{Binding Path=DataContext.FTitle, RelativeSource={RelativeSource FindAncestor,            AncestorType={x:Type UserControl}}}" 
     Background="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}"/> 

B)を駆動するように原稿を変更イメージにDataContextの移動 しようとした

<Border Margin="8,0,8,12.5" VerticalAlignment="top"> 
     <Image Source="{Binding Path=DataContext.Source, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}"/> 
                </Border>enter code here 

どちらも機能しませんでした。 (私は多くのバリエーションを試してみましたが、どれも働いた。

私は

答えて

0

{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}は、ツールチップのためのDataContextとしてUIElement(ListBoxItem)を結合する溶液のいずれかのために感謝するでしょう。それはあなたがListBoxItemのDataContextのを望んでいるようですその場合は、DataContextバインディングを次のように変更してください。{Binding Path=PlacementTarget.DataContext, RelativeSource={x:Static RelativeSource.Self}}

関連する問題