質問

Blend 4は、これが無効なマークアップであり、その理由を教えてくれないと言っています。

<ImageBrush Stretch="Fill"  ImageSource="{Binding Avatar, Mode=OneWay}"/>

Twitterフィードからデータを引き出し、ImagesOurceに保存し、それを画像ブラシにバインドして(以下を参照する)、長方形の塗りつぶしとして使用します。これがより多くのコンテキストです:

<Rectangle x:Name="Avatar" RadiusY="9" RadiusX="9" Width="45" Height="45"  VerticalAlignment="Center" HorizontalAlignment="Center" >
    <Rectangle.Fill>
       <ImageBrush Stretch="Fill"  ImageSource="{Binding Avatar, Mode=OneWay}"/>
    </Rectangle.Fill>
</Rectangle>

Silverlight usercontrolの内部でこれを使用しています。これは、Silverlightアプリケーションの内部で使用されています。問題が何であるかについてのアイデアはありますか?

役に立ちましたか?

解決

バインディングは、ImageBrushのImagesOurceなどに適用することはできません。私は同様の問題を抱えており、代替案を探しています。

他のヒント

ImageBrushのImagesSourceにバインドすることはできませんが、形状の塗りつぶしプロパティにバインドできます。したがって、次の動作:

<Rectangle Name="myRect" Fill="{Binding Avatar}"/>

このようなクラスで:

public class AvatarClass
{
    public ImageBrush Avatar { get; set; }
}

そして、このように背後にコードします:

 myRect.DataContext = new AvatarClass{ 
                       Avatar = new ImageBrush {
                        ImageSource = new BitmapImage(avatarUri)}};

ここに行きます:WPF / Silverlight

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:convertor="clr-namespace:WpfApplication1.Converters"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <convertor:RectangleImageFillConvertor x:Key="RectangleImageFillConvertor" />
    </Window.Resources>

    <Grid>
        <Rectangle  HorizontalAlignment="Center" 
                    RadiusX="10" 
                    RadiusY="10" 
                    Width="200"  
                    Height="200"
                    Fill="{Binding ImageUrl, Converter={StaticResource RectangleImageFillConvertor}}"/>
    </Grid>
</Window>

BlockQuote

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public string ImageUrl { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            ImageUrl = "http://www.deargrumpycat.com/wp-content/uploads/2013/02/Grumpy-Cat1.jpg";
        }
    }
}

BlockQuote BlockQuote

namespace WpfApplication1.Converters
{
    public class RectangleImageFillConvertor : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                return new ImageBrush(new BitmapImage(new Uri(value as string, UriKind.RelativeOrAbsolute)));
                 //if silverlight
                 //  return new ImageBrush{   ImageSource = new BitmapImage(new Uri(value as string, UriKind.RelativeOrAbsolute))};
            }
            catch
            {
                return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

enter image description here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top