2011-12-21 18 views
0

私はWP7プラットフォームに新しく、奇妙なものに直面しています。イメージを持つカスタムコンポーネントがあります。ここでは(下のカスタムコンポーネントの一部)カスタムコントロールでイメージを読み込む際に問題が発生する

<Rectangle x:Name="ImageForeground" Height="240" Width="240" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" 
       DataContext="{TemplateBinding Image}" 
       OpacityMask="{Binding Converter={StaticResource brushConverter}}" /> 

がbrushConverter

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     BitmapImage image = (BitmapImage)value; 
     ImageBrush imageBrush = new ImageBrush(); 
     if (image != null) 
     { 
      imageBrush.ImageSource = image; 
     } 
     return imageBrush; 
    } 

今私は

<rounded:RoundedImageView Image="/Images/image1.png"/> 

でページにカスタムコンポーネントを追加します。ここで奇妙な部分です。このコンポーネントは特定のpng画像のみを表示します!私は5つ全てを持っていて、すべてのBuild ActionプロパティはContentに設定されています。しかし、コントロールは、すべてではなく一部を読み込むだけです。私はそう

<Image Height="200" HorizontalAlignment="Left" Margin="54,17,0,0" Name="image3" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/Images/service_reload.png" /> 

それが動作するように、通常の画像コンポーネント内の画像を入れた場合でも、見知らぬ人です! WTF !!

どのようなアイデアですか?

+0

魅力のように働いた: 私はFillプロパティにバインドbrushConverterを添付し Horizo​​ntalAlignment = "Center" VerticalAlignment = "Center" DataContext = "Rectangle x:Name =" ImageForeground "は、OpacityMaskプロパティの代わりに、 {TemplateBinding Image} "塗りつぶし=" {バインディングコンバータ= {静的リソースbrushConverter}} " /> ' –

+0

ちょっと不思議です - 画像の代わりに矩形を使用するのはなぜですか? –

+0

@CoolDude - あなたは答えとしてあなたのコメントを投稿し、数日後にそれを受け入れることができます。 – keyboardP

答えて

0

は解決: 解決:私の代わりにOpacityMaskプロパティのRectangleのFillプロパティにバインドbrushConverterを添付し、それが解決

<Rectangle x:Name="ImageForeground" Height="240" Width="240" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{TemplateBinding Image}" Fill="{Binding Converter={StaticResource brushConverter}}" />