.net - WPF Button Images Show at Design Time but Not Run Time -
i have 2 images stored in resources folder have build action set resources , copy output directory set not copy. images "font.png" , "open.png". when view designer, images appear in buttons them too, however; when run application buttons empty. below xaml, doing wrong?
<window x:class="preferences" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:se="clr-namespace:therandomizerwpf.markupextensions" xmlns:res ="clr-namespace:therandomizerwpf.my" xmlns:clr="clr-namespace:system;assembly=mscorlib" title="preferences" icon="the randomizer.ico" height="227.509" width="453.736" windowstyle="threedborderwindow" resizemode="noresize" style="{dynamicresource resourcekey=windowstyle}" > <window.resources> <image x:key="font" source="pack://application,,,resources/resources/font.png" /> <image x:key="open" source="pack://application,,,resources/resources/open.png" /> </window.resources> <stackpanel orientation="vertical"> <dockpanel margin="3" style="{dynamicresource resourcekey=contentpanel}"> <checkbox name="chkautoupdate" content="auto update" margin="6,3,3,3" verticalalignment="center" /> </dockpanel> <dockpanel margin="3" style="{dynamicresource resourcekey=contentpanel}"> <label name="lblresultfont" verticalcontentalignment="center" width="160" margin="3" content="default result font" dockpanel.dock="left" /> <button name="btnresultfont" margin="3" height="22" width="22" dockpanel.dock="right" content="{staticresource resourcekey=font}" /> <textbox name="txtresultfont" margin="3" height="21" isreadonly="true" dockpanel.dock="left" /> </dockpanel> <dockpanel margin="3,3,3,0" style="{dynamicresource resourcekey=contentpanel}"> <label name="lbltempdirectory" verticalcontentalignment="center" width="160" margin="3" content="temporary directory" dockpanel.dock="left" /> <button name="btntempdirectory" margin="3" width="22" height="22" dockpanel.dock="right" content="{staticresource resourcekey=open}" /> <textbox name="txttempdirectory" margin="3" height="22" isreadonly="true" dockpanel.dock="left" /> </dockpanel> <dockpanel margin="3,0,3,0" style="{dynamicresource resourcekey=contentpanel}"> <label name="lblcustomgrammardirectory" verticalcontentalignment="center" width="160" margin="3" content="custom grammar directory" dockpanel.dock="left" /> <button name="btncustomgrammardirectory" margin="3" width="22" height="22" dockpanel.dock="right" content="{staticresource resourcekey=open}" /> <textbox name="txtcustomgrammardirectory" margin="3" height="21" isreadonly="true" dockpanel.dock="left" /> </dockpanel> <dockpanel margin="3,0,3,3" style="{dynamicresource resourcekey=contentpanel}"> <label name="lblthemedirectory" verticalcontentalignment="center" width="160" margin="3" content="theme directory" dockpanel.dock="left" /> <button name="btnthemedirectory" margin="3" width="22" height="22" dockpanel.dock="right" content="{staticresource resourcekey=open}" /> <textbox name="txtthemedirectory" margin="3" height="21" isreadonly="true" dockpanel.dock="left" /> </dockpanel> <dockpanel margin="3" lastchildfill="false"> <button name="btnok" style="{dynamicresource resourcekey=actionbutton}" dockpanel.dock="right" width="80" margin="3" content="_ok" isdefault="true" /> <button name="btncancel" style="{dynamicresource resourcekey=actionbutton}" dockpanel.dock="right" width="80" margin="3" content="_cancel" iscancel="true" /> </dockpanel> </stackpanel> </window>
i think image source uri has incorrect format. should like
pack://application:,,,/subfolder/resourcefile.xaml
(note colon after "application")
what having
source="subfolder/resourcefile.png"
which simpler, more readable, , works ;-)
Comments
Post a Comment