1

シルバーライト5でのみマウスオーバーで画像を表示する必要があります。誰か助けてください。それを達成する方法を教えてください...

<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>

ネオン

4

1 に答える 1

0

多くの方法があります。OnFocus は画像の Visibility Visible を設定し、FocusLeft は基本的にメイン要素の Collapsed を設定します。

しかし、サンプルの DataTemplate にあることがわかります。

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

1)次のようなDataTemplateの要素の代わりに新しいコンポーネントを作成します

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);
        }
    }
}

次に、xamlで次のように使用します

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

2) GotoStateAction 動作 http://msdn.microsoft.com/en-us/library/ff723953%28v=expression.40%29.aspxを使用しますが、DataTemplate にあり、これを使用するのは簡単ではないことがわかります。

3) MainElement.FinChildByType < StackPanel >().FirstOrDefault() が null でない場合は、分離コードでこの要素にフォーカスおよびフォーカス解除ハンドラーを追加します。しかし、これは私がほとんど使用しない方法です。

テンプレート内にあるため、テンプレート内の名前付きオブジェクトが分離コードに表示されないため、少し難しくなります。

希望が役立ちます

于 2012-05-03T11:54:55.747 に答える