2013-10-01 3 views

답변

3

많은 다른 장소에서 재사용 할 계획이라면 CustomControl을 만드는 것이 더 쉽습니다.
여기 그렇게해야 작은 사용자 컨트롤입니다 :

<UserControl x:Class="PhoneApp1.ImageWithLoading" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    d:DesignHeight="480" d:DesignWidth="480" 
      x:Name="myImageWithLoading"> 

    <Grid x:Name="LayoutRoot" > 
     <Image x:Name="temporaryImage" Source="/Assets/Loading"/> 
     <Image Source="{Binding Source,ElementName=myImageWithLoading}" ImageOpened="RemoteImage_OnLoaded"/> 
    </Grid> 
</UserControl> 



public partial class ImageWithLoading : UserControl 
{ 
    public static readonly DependencyProperty SourceProperty = 
     DependencyProperty.Register("Source", typeof (ImageSource), typeof (ImageWithLoading), new PropertyMetadata(default(ImageSource))); 

    public ImageSource Source 
    { 
     get { return (ImageSource) GetValue(SourceProperty); } 
     set { SetValue(SourceProperty, value); } 
    } 
    public ImageWithLoading() 
    { 
     InitializeComponent(); 
    } 

    private void RemoteImage_OnLoaded(object sender, RoutedEventArgs e) 
    { 
     temporaryImage.Visibility = Visibility.Collapsed; 
    } 
} 
+0

답장을 보내 주셔서 감사합니다. :) –

+0

답장을 보내 주셔서 감사합니다. 그것은 나를 위해 완벽하게 작동했습니다. 나는 ImageBrush에 대해서 똑같은 시도를하고있다. 나는 ** Ellipse **를 가지고있다. 'Ellipse.Fill' 속성에서 ImageBrush를 추가했습니다. 'ImageBrush'에 어떻게 코드를 사용할 수 있습니까? –

2

또 다른 옵션은 너무

<Style TargetType="Image"> 
    <Setter Property="Source" Value="/Assets/Load.jpg"/> 
</Style> 

같은 기본 스타일 페이지의 이미지에 대한 기본 스타일을 생성하는 그냥 소스를 설정할 수 있습니다 이미지가 준비되면

관련 문제