1
import wpf

from System.Windows import Application, Window,MessageBox
from Main import *
from Sign_Up import *

import System
from System.Windows.Controls import *
from System.Windows.Input import *
from System import Uri
from System.Windows.Media.Imaging import BitmapImage
from System.Windows.Media import ImageBrush

class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'Sign_In.xaml')
        brush = ImageBrush()
        image = Image()
        image.Source = BitmapImage(Uri("C:\Users\Chen\Pictures\1-150511225359.jpg"))
        brush.ImageSource = image.Source
        self.SignUpGrid.Background = brush

I tried setting the background image of a window in wpf IronPython and I keep getting syntax errors.

2
  • What errors did you get? Commented Oct 22, 2015 at 19:19
  • I'm working on visual studio and on IronPython it only gives me general error areas and not the error Commented Oct 22, 2015 at 19:28

1 Answer 1

1

You should use double \ in path names. And you don't need the intermediate Image control.

def __init__(self):
    wpf.LoadComponent(self, 'Sign_In.xaml')
    brush = ImageBrush()
    brush.ImageSource = BitmapImage(Uri("C:\\Users\\Chen\\Pictures\\1-150511225359.jpg"))
    self.SignUpGrid.Background = brush

Or even shorter:

def __init__(self):
    wpf.LoadComponent(self, 'Sign_In.xaml')
    self.SignUpGrid.Background = ImageBrush(BitmapImage(Uri(
        "C:\\Users\\Chen\\Pictures\\1-150511225359.jpg")))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.