how can I set a background image in code?

前端 未结 1 812
半阙折子戏
半阙折子戏 2020-12-12 05:54

If I want to set a image as background on a textBox I can use this code in the axml:


 
    

        
相关标签:
1条回答
  • 2020-12-12 06:14

    Provided that MyImage.jpg is a file in the application's current folder, you could write

    myTextBox.Background = new ImageBrush(new BitmapImage(new Uri("MyImage.jpg")));
    

    If it's a Resource File, you would have to use a Resource File Pack URI:

    myTextBox.Background =
        new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/MyImage.jpg")));
    
    0 讨论(0)
提交回复
热议问题