vb.net - WPF load background image on form -
hey have following code supposed take jpg image , place on background of form. however, see black background.
dim mybrush new imagebrush() dim image new image() dim grid new grid() image.source = new bitmapimage(new uri("pack://application:,,,/wpfapplication1;component/resources/1680-logoless.jpg")) mybrush.imagesource = image.source grid.background = mybrush
and current xaml:
<window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:wpfapplication1" mc:ignorable="d" title="mainwindow" height="350" width="525"> <grid> <textbox x:name="textbox1" horizontalalignment="left" height="23" textwrapping="wrap" text="textbox" verticalalignment="top" width="120" margin="157,145,0,0"/> <label x:name="label1" content="label" horizontalalignment="left" margin="68,59,0,0" verticalalignment="top" width="111"/> <button x:name="button" content="button" horizontalalignment="left" verticalalignment="top" width="75" margin="335,62,0,0"/> <button x:name="button1" content="encrypt" horizontalalignment="left" height="17" margin="335,123,0,0" verticalalignment="top" width="120"/> <textbox x:name="toencrypt" horizontalalignment="left" height="23" textwrapping="wrap" text="textbox" verticalalignment="top" width="172" margin="335,145,0,0"/> <textbox x:name="todecrypt" horizontalalignment="left" height="23" textwrapping="wrap" text="textbox" verticalalignment="top" width="172" margin="335,173,0,0"/> <button x:name="button2" content="decrypt" horizontalalignment="left" height="23" margin="335,201,0,0" verticalalignment="top" width="120"/> </grid> </window>
anyone see missing?
set x:name
attribute of grid in xaml, create field in mainwindow class:
<window ...> <grid x:name="rootgrid"> ... </grid> </window>
then, instead of creating new grid instance, set background of 1 declared in xaml:
rootgrid.background = new imagebrush(new bitmapimage( new uri("pack://application:,,,/resources/1680-logoless.jpg")))
Comments
Post a Comment