2017-05-11 3 views
0

私は this other postツールヒントは、

私は、@ grek40の指示に従ってそれをしなかったし、それがうまく機能で説明したようにキャンバス内の要素を描画するアプリケーションをプログラムしました。

ここでは、キャンバスに描画された要素にツールチップを追加したいと思います(Borderクラスで表されるTasks要素のみ)。これは私のコードです:

<DataTemplate DataType="{x:Type local:TaskItem}"> 
    <Border 
    Background="#0074D9" 
    BorderBrush="#001F3F" 
    BorderThickness="2" 
    Width="{Binding Width}" 
    Height="{Binding Height}"> 
     <TextBlock 
     Text="{Binding Id}" 
     FontSize="20" 
     Foreground="White" 
     HorizontalAlignment="Center" VerticalAlignment="Center"/> 
     <Border.ToolTip> 
      <ToolTip Background="#D5F0F0FF"> 
       <StackPanel> 
        <TextBlock Text="Reading Suggestion" FontWeight="Bold"/> 
        <TextBlock Text="Charles Dickens" Margin="5"/> 
       </StackPanel> 
      </ToolTip> 
     </Border.ToolTip> 
    </Border> 
</DataTemplate> 

しかし、それは動作しません。タスク要素(罫線項目)をホバーすると何も起こりません。どのようなアイデアが間違っている?

UPDATE

グリッド(X:NAME = "GRID1")はズーミング及びパディング処理カスタムコントロールに含まれています。 this post in codeplexの後に実装しました(私は 'Simple Sample Code'に従いました)。

だから私のXAMLは、次のようになります。

<ScrollViewer 
    x:Name="scroller" 
    CanContentScroll="True" 
    VerticalScrollBarVisibility="Visible" 
    HorizontalScrollBarVisibility="Visible" 
    > 

    <!-- 
    This is the control that handles zooming and panning. 
    --> 
    <ZoomAndPan:ZoomAndPanControl     
     x:Name="zoomAndPanControl" 
     Background="LightGray" 
     MouseDown="zoomAndPanControl_MouseDown" 
     MouseUp="zoomAndPanControl_MouseUp" 
     MouseMove="zoomAndPanControl_MouseMove" 
     MouseWheel="zoomAndPanControl_MouseWheel" 
     > 

     <!-- 
     This Canvas is the content that is displayed by the ZoomAndPanControl. 
     Width and Height determine the size of the content. 
     --> 
     <Grid x:Name="grid1"> 
      <ItemsControl x:Name="content" 
       ItemsSource="{Binding TaskItems}" 
       ItemContainerStyle="{StaticResource canvasTaskItemStyle}"> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <Canvas 
          Background="White" 
          Height="2000" 
          Width="2000"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
      </ItemsControl> 
      <ItemsControl x:Name="contentLines" 
       ItemsSource="{Binding TaskLineItems}">      
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <Canvas 
          Background="Transparent" 
          Height="2000" 
          Width="2000"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
      </ItemsControl> 
     </Grid> 
    </ZoomAndPan:ZoomAndPanControl> 

</ScrollViewer> 

は多分、ツールチップに干渉ZoomAndPanControlのコマンドはありますか?

+0

よろしいですか?私はちょうど私の例にツールヒントをマージし、問題なく表示されます。おそらくあなたのプロジェクトの他の部分が干渉しているのでしょうか? – grek40

+0

これは、ズームとパンを処理するカスタムコントロールの中にコードがあるためです。私はそれに関する情報を投稿に更新しました。ありがとう – chincheta73

答えて

0

グリッド内に2つの異なるアイテムコントロールがオーバーレイされています。一番上のコントロールは行を管理し、Background="Transparent"があるため、すべてのマウストラフィックがキャプチャされ、基本的なタスクアイテムコレクションはマウスを受け取ることはありません。

解決策1(ハッキー):商品または行の注文またはZインデックスを交換します。

溶液2(もハック):代わりに透明(Background="{x:Null}"

溶液3(以下ハック)製造の遮断の背景を削除する:データコンテキストにおいて、行及びtaskitems両方を含む複合アイテムのコレクションを作成します単一のキャンバスを使用してそれらを提示します。溶液3を実装する

一つの方法は、背後にあるコードでアイテムを組み合わせることで、他はCompositeCollectionの使用である:

<ItemsControl ...> 
    <ItemsControl.ItemsSource> 
     <CompositeCollection> 
      <CollectionContainer Collection="{Binding TaskItems}"/> 
      <CollectionContainer Collection="{Binding TaskLineItems}"/> 
     </CompositeCollection> 
    </ItemsControl.ItemsSource> 
    ... 
</ItemsControl> 
+0

おかげさまで@ grek40私は解決策3を行いました:) – chincheta73

+0

@ chincheta73問題はありません、私の編集を参照してください多くのeffordなしで結合されたコレクションを作成する方法を参照してください。 – grek40

0

リンク先の記事の回答から、ItemsControlのアイテムにこのテンプレートを使用しているようです。 ItemsControlは、各項目をItemContainerStyleプロパティで定義されたコンテナのスタイルでコンテナに配置します。

ItemContainerStyleにアイテムを追加する代わりに、ツールチップをアイテムの代わりにコンテナに入れてみてください。もう1つの投稿ではcanvasTaskItemStyleです。

<Style x:Key="canvasTaskItemStyle" TargetType="ContentPresenter"> 
    <Setter Property="Canvas.Left" Value="{Binding CoordX}"/> 
    <Setter Property="Canvas.Top" Value="{Binding CoordY}"/> 
    <Setter Property="ToolTip"> 
     <Setter.Value> 
      <ToolTip Background="#D5F0F0FF"> 
       <StackPanel> 
        <TextBlock Text="Reading Suggestion" FontWeight="Bold"/> 
        <TextBlock Text="Charles Dickens" Margin="5"/> 
       </StackPanel> 
      </ToolTip> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

まだ動作しません。たぶん、プロジェクトの@ grek40another部分が示唆しているように、干渉しています。 – chincheta73

関連する問題