2011-01-19 8 views
5

イメージコントロールの上にマウスがあるときは、ポップアップを表示します。だから私は、コントロールテンプレートを作成し、それは次のようになります。私がしようとした場合、私はどのように私はまた、コントロールテンプレート イメージコントロールの上にマウスがあるときにポップアップ表示

  • に画像ソースにアクセスもできません

    1.  <ControlTemplate x:Key="AvatarImageTemplate" TargetType="{x:Type Image}"> 
            <Grid> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition></ColumnDefinition> 
             </Grid.ColumnDefinitions> 
             <Grid.RowDefinitions> 
              <RowDefinition></RowDefinition> 
              <RowDefinition></RowDefinition> 
             </Grid.RowDefinitions> 
      
             <HERE I WANT IMAGE SOURCE Grid.Row="0"/> 
             <Popup IsOpen="False" 
                Name="OponentImagePopUp"        
                AllowsTransparency="True" 
                PopupAnimation="Slide" 
                HorizontalOffset="-35" 
                VerticalOffset="0" 
                Grid.Row="1"> 
              <Border BorderThickness="1" 
                 BorderBrush="Black"> 
               <Grid Height="350" MinWidth="350"> 
                <Grid.Background> 
                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.3"> 
                  <LinearGradientBrush.GradientStops> 
                   <GradientStop Color="LightGray" Offset="0"/> 
                   <GradientStop Color="WhiteSmoke" Offset="1"/> 
                  </LinearGradientBrush.GradientStops> 
                 </LinearGradientBrush> 
                </Grid.Background> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition Width="75"></ColumnDefinition> 
                 <ColumnDefinition Width="*"></ColumnDefinition> 
                </Grid.ColumnDefinitions> 
                <Grid.RowDefinitions> 
                 <RowDefinition Height="*"></RowDefinition> 
                </Grid.RowDefinitions> 
      
                <Border BorderThickness="1" 
                  BorderBrush="Black" 
                  Background="White" 
                  Margin="4,4,4,4" 
                  Grid.Column="0"> 
                 <Image Margin="2,2,2,2"> 
                  <Image.Source > 
                   <MultiBinding Converter="{StaticResource avatarConverter}"> 
                    <Binding Path="ProfilePhoto"></Binding> 
                    <Binding Path="StatusInfo.IsLogged"></Binding> 
                   </MultiBinding> 
                  </Image.Source> 
                 </Image> 
                </Border> 
               </Grid> 
              </Border> 
             </Popup> 
            </Grid> 
            <ControlTemplate.Triggers> 
             <Trigger Property="IsMouseOver" Value="True"> 
              <Setter TargetName="OponentImagePopUp" Property="IsOpen" Value="True" /> 
             </Trigger> 
            </ControlTemplate.Triggers> 
           </ControlTemplate> 
      

      を私は2つの問題を抱えていますイメージコントロールでスタイルを作成し、プロパティテンプレート - >画像コントロールにプロパティテンプレートを設定しないでください。

    私の目指すのは、同じ画像だけの大きな画像です。

    EDIT:

    私はここにある、イメージコントロールを持ってアドバイス氏Glazkov、として、簡単なコントロールを作成します。後ろの

    <UserControl x:Class="Spirit.Controls.AvatarImageControl" 
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          mc:Ignorable="d" 
          d:DesignHeight="300" d:DesignWidth="300"> 
        <Grid> 
         <Image x:Name="SmallImage" 
          Source="{Binding ElementName=root, Path=ImageSource}" 
          Stretch="Fill"/> 
        </Grid> 
    </UserControl> 
    

    コードが同じである:

    public partial class AvatarImageControl : UserControl 
        { 
         public AvatarImageControl() 
         { 
          InitializeComponent(); 
         } 
    
         public ImageSource ImageSource 
         { 
          get { return (ImageSource)GetValue(ImageSourceProperty); } 
          set { SetValue(ImageSourceProperty, value); } 
         } 
    
         public static readonly DependencyProperty ImageSourceProperty = 
          DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(AvatarImageControl), new UIPropertyMetadata(null)); 
    
        } 
    

    私はこの表示を見てください:

    <Grid Background="#99CCFF" Margin="4,4,4,4"> 
         <Controls:AvatarImageControl ImageSource="{Binding Path=Oponent.Info.ProfilePhoto,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/> 
    </Grid> 
    

    私はAvatarImageControlのImageSourceにUriのプロパティタイプをバインドします。

    私は何が悪いですか?

    また、私は、ユーザーコントロールでこれを試してみてください。

    <Grid> 
        <Image x:Name="SmallImage" 
         Source="{Binding Path=ImageSource, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
         Stretch="Fill"/> 
    </Grid> 
    

    結果は同じです。

    私はビューでユーザーコントロールを使用していますが、私はUriのビューモデルタイプからImageSourceプロパティプロパティをバインドします。他に何もない。

    EDIT 2:ミスターGlazkovプロデュース例外の コード:

    {"Set property 'System.Windows.Controls.Primitives.Popup.IsOpen' threw an exception."} 
    {"A TwoWay or OneWayToSource binding cannot work on the read-only property 'IsMouseOver' of type 'System.Windows.Controls.Image'."} 
    StackTrace: 
        at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) 
        at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
        at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 
        at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 
        at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) 
        at Spirit.Controls.AvatarImageControl.InitializeComponent() in c:\Users\Jan\Documents\Visual Studio 2010\Projects\BACKUP\Pokec__Messenger\Spirit_Caliburn_Micro_v1.0\Controls\AvatarImageControl.xaml:line 1 
        at Spirit.Controls.AvatarImageControl..ctor() in C:\Users\Jan\Documents\Visual Studio 2010\Projects\BACKUP\Pokec__Messenger\Spirit_Caliburn_Micro_v1.0\Controls\AvatarImageControl.xaml.cs:line 24 
    

    ソリューションは、次のとおりです。一方向にモードを結合

    <Popup IsOpen="{Binding ElementName=SmallImage, Path=IsMouseOver, Mode=OneWay}"> 
    

    セット。

    良いです。

    Glazkovさんにお礼を申し上げます。

  • +0

    あなたのユーザーコントロールに名前を指定するのを忘れて(私の答えにライン4を参照してください):x:Name = "root" –

    +0

    沖、私はこの問題をまだ修復しています。 –

    +0

    ええ、バインディングモードを忘れました...私の答えを更新しました。 –

    答えて

    9

    Controlから派生したものではないため、イメージコントロールのコントロールテンプレートを定義できません。したがって、コントロールテンプレートはありません。これは、OnRenderメソッドでレンダリングされます。

    あなたができることは、1つの依存関係プロパティImageSourceを持つユーザーコントロールを作成することです。ここでは、このコントロールのXAMLは次のとおりです。

    <UserControl x:Class="AvatarImage" 
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
          x:Name="root"> 
        <Grid> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition></ColumnDefinition> 
         </Grid.ColumnDefinitions> 
         <Grid.RowDefinitions> 
          <RowDefinition></RowDefinition> 
          <RowDefinition></RowDefinition> 
         </Grid.RowDefinitions> 
    
         <Image x:Name="SmallImage" 
           Source="{Binding ElementName=root, Path=ImageSource}" 
           Grid.Row="0" /> 
         <Popup IsOpen="{Binding ElementName=SmallImage, Path=IsMouseOver, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
           Name="OponentImagePopUp" 
           AllowsTransparency="True" 
           PopupAnimation="Slide" 
           HorizontalOffset="-35" 
           VerticalOffset="0" 
           Grid.Row="1"> 
          <Border BorderThickness="1" 
            BorderBrush="Black"> 
           <Grid Height="350" 
             MinWidth="350"> 
            <Grid.Background> 
             <LinearGradientBrush StartPoint="0,0" 
                  EndPoint="0,0.3"> 
              <LinearGradientBrush.GradientStops> 
               <GradientStop Color="LightGray" 
                   Offset="0" /> 
               <GradientStop Color="WhiteSmoke" 
                   Offset="1" /> 
              </LinearGradientBrush.GradientStops> 
             </LinearGradientBrush> 
            </Grid.Background> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Width="75"></ColumnDefinition> 
             <ColumnDefinition Width="*"></ColumnDefinition> 
            </Grid.ColumnDefinitions> 
            <Grid.RowDefinitions> 
             <RowDefinition Height="*"></RowDefinition> 
            </Grid.RowDefinitions> 
    
            <Border BorderThickness="1" 
              BorderBrush="Black" 
              Background="White" 
              Margin="4,4,4,4" 
              Grid.Column="0"> 
             <Image Margin="2,2,2,2"> 
              <Image.Source> 
               <MultiBinding Converter="{StaticResource avatarConverter}"> 
                <Binding Path="ProfilePhoto"></Binding> 
                <Binding Path="StatusInfo.IsLogged"></Binding> 
               </MultiBinding> 
              </Image.Source> 
             </Image> 
            </Border> 
           </Grid> 
          </Border> 
         </Popup> 
        </Grid> 
    </UserControl> 
    

    そしてここでは、コードは(AvatarImage.xaml.cs)の背後にある:

    public partial class AvatarImage : UserControl 
    { 
        public AvatarImage() { 
         InitializeComponent(); 
        } 
    
        public ImageSource ImageSource { 
         get { return (ImageSource)GetValue(ImageSourceProperty); } 
         set { SetValue(ImageSourceProperty, value); } 
        } 
    
        public static readonly DependencyProperty ImageSourceProperty = 
         DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(AvatarImage), new UIPropertyMetadata(null)); 
    } 
    
    +0

    Gj、素敵で完全な答えは、同様にUserControlを提案するつもりだった。 –

    +0

    Glazkov氏あなたのソリューションを試してみますが、私は何が悪いのか分かりません。 –

    +0

    あなたの投稿に私のコメントを見てください。また、ここでそれを繰り返します: "あなたのUserControlで名前を指定するのを忘れてしまった(私の答えの4行目を参照):x:Name =" root "" –

    4

    これまでの一般的なアプローチ:

    <CONTROL> 
         <Grid> 
          <!-- Actual control content --> 
          <Popup IsOpen="{Binding RelativeSource={RelativeSource AncestorType=CONTROL}, Path=IsMouseOver, Mode=OneWay}"> 
           <!-- Popup content --> 
          </Popup> 
         </Grid> 
        </CONTROL> 
    

    あなたはあなただけの祖先型の画像を検索し、同様RelativeSourceは結合を介して画像ソースにアクセスすることができます。

    編集:あなたの質問がちょっと整理されましたので、私はあなたの2つの特定の問題のコードを見つけようとすることができます。
    編集2:

    関連する問題