0

Caliburn.Microで動的な背景画像を使用したいと思っていました。これは私が成功せずに試したことです。

<Grid>
 <Grid.Background>
   <ImageBrush x:Name="MyPhoto" /> 
 </Grid.Background>
</Grid>

//some view model
public class ImageViewModel
{
   public ImageSource MyPhoto {get;set;}
}

//Add Convention
//App.XAML.cs
...
public override void Configure()
{
  ...

        ConventionManager.AddElementConvention<ImageBrush>(ImageBrush.ImageSourceProperty, "ImageSource", "Loaded");
  ...
}

ImageBrushのImageSourceをCaliburn.Microとバインドすることは可能ですか、それともこれを行うためのより良い方法がありますか?

4

1 に答える 1

2

わかりませんが、 sではなくsAddElementConventionでのみ機能すると思います。ただし、これは機能するはずです。UIElementDependencyObject

MainPage.xaml

<Grid x:Name="MyBrush">
</Grid>

MainPageViewModel.cs

public class MainPageViewModel : Screen
{
    public MainPageViewModel()
    {
        MyPhoto = new BitmapImage(new Uri("ms-appx:///Assets/SplashScreen.png"));
    }

    public ImageSource MyPhoto { get; set; }

    public ImageBrush MyBrush
    {
        get
        {
            ImageBrush brush = new ImageBrush();
            brush.ImageSource = MyPhoto;
            return brush;
        }
    }
}

App.xaml.cs

protected override void Configure()
{
    container = new WinRTContainer();
    container.RegisterWinRTServices();

    ConventionManager.AddElementConvention<Grid>(Grid.BackgroundProperty, "Background", "Loaded");
}

または、XAMLで手動でバインドを行うこともできます。

<Grid>
    <Grid.Background>
        <ImageBrush ImageSource="{Binding MyPhoto}" /> 
    </Grid.Background>
</Grid>
于 2012-12-07T06:21:14.677 に答える