c# - Image not displaying XAML -


i created own button has icon on side , text on other problem image not displaying. did miss here? appreciated. tia

this xaml of control.

<usercontrol x:name="qbuttoncontrol"     x:class="commonlayout.qbutton"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="using:commonlayout"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     mc:ignorable="d"     d:designheight="36"     d:designwidth="145" minwidth="145" minheight="36" loaded="qbuttoncontrol_loaded">      <grid pointerentered="grid_pointerentered_1" pointerexited="grid_pointerexited_1" minwidth="145" minheight="36" background="#ffdcd1d1">         <textblock x:name="btnlabel" height="20" margin="36,8,4,8" textwrapping="wrap" text="text here" verticalalignment="center" fontsize="18.667" width="105"/>         <image x:name="img" horizontalalignment="left" height="27" margin="1,4,0,0" verticalalignment="top" width="29"/>      </grid> </usercontrol> 

this code behind control.

public sealed partial class qbutton : usercontrol     {         private imagesource icondefault;         private brush hoverbrush = new solidcolorbrush(color.fromargb(255, 228, 228, 228));          public string text         {                         {                 return btnlabel.text;             }             set             {                 btnlabel.text = value;             }         }          public imagesource icon         {                         {                 return icondefault;             }             set             {                 icondefault = value;                 img.source = value;             }         }          public brush hoverbrush         {                         {                 return hoverbrush;             }             set             {                 hoverbrush = value;             }         }          public qbutton()         {             this.initializecomponent();         }          private void grid_pointerentered_1(object sender, pointerroutedeventargs e)         {             btnlabel.foreground = hoverbrush;         }          private void grid_pointerexited_1(object sender, pointerroutedeventargs e)         {             btnlabel.foreground = foreground;         }          private void qbuttoncontrol_loaded(object sender, routedeventargs e)         {             img.source = icondefault;                }       } 

first of all, not use hard coded file path image.
windows store apps run in sandbox, not able arbitrary file location when deploy app.

second, can't use backslashes in image uri. backslashes technical reason setting error getting. changing forward slashes in not answer.

access image in xaml

if add image projects /assets folder, can use xaml show in qbutton.

<local:qbutton x:name='qbutton1'                icon='/assets/jellyfish.jpg'  /> 

in code

to change icon in code.

public mainpage() {   this.initializecomponent();   this.loaded += mainpage_loaded;  }  private async void mainpage_loaded(object sender, routedeventargs e) {   var file = await storagefile.getfilefromapplicationuriasync(new uri("ms-appx:///assets/shrimp.jpg"));   var filestream = await file.openasync(windows.storage.fileaccessmode.read);    var image = new bitmapimage();    image.setsource(filestream);    qbutton1.icon = image;     } 

if want user choose image computer @ runtime, @ file pickers.

msdn file pickers


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -