xaml - Powershell WPF Forms changing textbox background to an image -


i trying make background of text box image in powershell. im using xaml converter http://blogs.technet.com/b/heyscriptingguy/archive/2014/08/01/i-39-ve-got-a-powershell-secret-adding-a-gui-to-scripts.aspx load xaml form:

<window      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="uat" height="300" width="300">     <grid>         <button name="btngo" content="go" horizontalalignment="left" verticalalignment="top" width="75" margin="207,240,0,0"/>         <textbox name="txtout" horizontalalignment="left" height="233" textwrapping="wrap" text="textbox" verticalalignment="top" width="272" margin="10,0,0,0"/>     </grid> </window> 

the .ps1 file:

add-type –assemblyname presentationframework add-type –assemblyname presentationcore add-type –assemblyname windowsbase  .\loaddialog.ps1 -xamlpath '.\uat.xaml' 2>> errors.txt  $txtout.text = ""  $btngo.add_click({     $txtout.text = ""     $image = new-object system.windows.media.brush     $image = ".\bg1.png" #.source     $txtout.background = $image })  $xamgui.showdialog() | out-null 2>> errors.txt  

i error:

new-object : constructor not found. cannot find appropriate constructor type system.windows.media.brush. @ uat.ps1:40 char:24 +     $image = new-object <<<<  system.windows.media.brush + categoryinfo          : objectnotfound: (:) [new-object], psargumentexception + fullyqualifiederrorid : cannotfindappropriatector,microsoft.powershell.commands.newobjectcommand  exception setting "background": "cannot convert value ".\bg1.png" type "system.windows.media.brush". error: "token not valid."" @ uat.ps1:44 char:13 +     $txtout. <<<< background = $image + categoryinfo          : invalidoperation: (:) [], runtimeexception + fullyqualifiederrorid : propertyassignmentexception 

i'm loading: presentationframework, presentationcore, windowsbase

what missing? there better way this?

here example works me. it's bit convoluted, that's wpf, me anyway.

you have define uri (path image). based on load bitmapimage , use create imagebrush. can in turn set background of text box.

add-type –assemblyname windowsbase add-type –assemblyname presentationcore add-type –assemblyname presentationframework  [xml]$xaml = @'  <window      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="uat" height="300" width="300">     <grid>         <button name="btngo" content="go" horizontalalignment="left" verticalalignment="top" width="75" margin="207,240,0,0"/>         <textbox name="txtout" horizontalalignment="left" height="233" textwrapping="wrap" text="textbox" verticalalignment="top" width="272" margin="10,0,0,0"/>     </grid> </window> '@  $reader=(new-object xml.xmlnodereader $xaml)  $mainform=[windows.markup.xamlreader]::load( $reader )   $xaml.selectnodes("//*[@name]") | %{set-variable -name ($_.name) -value $mainform.findname($_.name) -scope global}  $btngo.add_click({     $txtout.text = ""     $uri = new-object system.uri("d:\documents\map - discovery.png")     $imagesource = new-object system.windows.media.imaging.bitmapimage $uri      $imagebrush = new-object system.windows.media.imagebrush  $imagesource     $txtout.background = $imagebrush })  $mainform.showdialog() | out-null 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -