2012-05-03 6 views
1

銀色の上にマウスで画像を表示する必要があります。 誰でも助けてください。 は、多くの方法がありますが...私に銀色のデータグリッドにマウスを置いて画像を表示する方法

<sdk:DataGridTemplateColumn x:Name="colDeleteContent" IsReadOnly="True" Header="Delete Content" Width="100" CanUserResize="False"> 
<sdk:DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
    <StackPanel x:Name="spDeleteContent" VerticalAlignment="Center" Margin="10,0,0,0" Width="20" Height="20" HorizontalAlignment="Center" Orientation="Vertical">                
    <Image x:Name="imgDeleteContent" Source="Assets/Images/close.png" Height="15" Width="15" Margin="0" MouseLeftButtonDown="imgDeleteContent_MouseLeftButtonDown" Cursor="Hand"/>                
    </StackPanel> 
    </DataTemplate> 
</sdk:DataGridTemplateColumn.CellTemplate> 
</sdk:DataGridTemplateColumn> 

ネオン

答えて

0

それを達成するためにどのように任意のアイデアを与える、ONFOCUSは可視性可視あなたの主な要素の基本的折りたたみFocusLeftセットにあなたのイメージを設定します。

しかし、それはあなたのサンプルのDataTemplate上にあることがわかります。

だから私は想像するいくつかの方法があります。

1)など

<DataTemplate> 
    <local:StackPanelHasHiddenImage Image="/ProjectBus;component/blabal.png"/> 
</DataTemplate> 

2)使用GotoStateAction行動 http://msdn.microsoft.com/en-us/library/ff723953%28v=expression.40%29.aspxのようなあなたのXAMLの使用におけるその後

namespace ProjectBus 
{ 

    public class StackPanelHasHiddenImage : Control 
    { 
     //You may don't need dependency property 
     //It supports bindability 
     #region dependency property 
     public static Image GetMyProperty(DependencyObject obj) 
     { 
      return (Image)obj.GetValue(ImageProperty); 
     } 

     public static void SetMyProperty(DependencyObject obj, Image value) 
     { 
      obj.SetValue(ImageProperty, value); 
     } 

     // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... 
     public static readonly DependencyProperty ImageProperty = 
      DependencyProperty.RegisterAttached("Image", typeof(Image), typeof(StackPanelHasHiddenImage), new System.Windows.PropertyMetadata(null)); 
     #endregion 

     public Image Image 
     { 
      get; 
      set; 
     } 

     protected override void OnGotFocus(RoutedEventArgs e) 
     { 
      Image.Visibility = Visibility.Visible; 
      base.OnGotFocus(e); 
     } 
     protected override void OnLostFocus(RoutedEventArgs e) 
     { 
      Image.Visibility = Visibility.Collapsed; 
      base.OnLostFocus(e); 
     } 
    } 
} 

としてのDataTemplateではなく要素の新しいコンポーネントを作成しますが、私はその中にいることがわかりDataTemplateを使用してこれを使用する方が簡単ではないかもしれません。

3)MainElement.FinChildByType < StackPanel>()。FirstOrDefault()がnullでない場合、コードビハインドのこの要素にフォーカスおよび非フォーカスハンドラを追加します。しかし、これは主に私が使用することを避ける方法です。

テンプレート内の名前付きオブジェクトがコードビハインドに表示されないようにするため、そのビットは少し難しくなります。

希望は

+0

お返事ありがとうございます。私はあなたのコードを試してみます。 – Arun

+0

あなたのコードを試しました。 の名前空間は何ですか? Plsヘルプ... – Arun

+0

パート1を編集しました。クラスStackPanelHasHiddenImageクラスの名前空間がXAMLのProjectBusであるとします.xmlns:local = "clr-namespace:ProjectBus"にxmlnsが定義されています。ローカルは予約語ではありませんが、これは私が作ったものです。 ProjectBus.Controlsのようなネームスペースでコントロールを収集し、次にxamns:宣言的にコード化する xmlns:controls: "clr-namespace:ProjectBus.Controls"を追加するような使い方をしてください。 –

関連する問題