c# - How to use variable outside the main window class -


<window x:class="shelfmapping.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="shelf mapping" height="800" width="1320"         loaded="window_loaded" unloaded="window_unloaded">     <grid>         <image name="camera" width="640" height="480" margin="10,10,662,279" />          <image name="depthout"  height="480"  width="640" margin="667,10,5,289"/>         <canvas name="canvas" width="640" height="480" margin="667,10,5,289"/>         <button content="screenshot" horizontalalignment="left" margin="298,649,0,0" verticalalignment="top" width="75" click="buttonscreenshotclick"/>         <textbox name="txtcode" horizontalalignment="left" height="101" margin="901,514,0,0" textwrapping="wrap" text="" verticalalignment="top" width="223"/>         <button content="ocr" horizontalalignment="left" margin="486,649,0,0" verticalalignment="top" width="75" rendertransformorigin="-0.205,0.304" click="click_ocr"/>      </grid> </window> 

this xaml code. want use canvas variable outside main window class. don't know how use variable outside mainwindow.cs.

non fancy way 1:

xaml (x) namespace has property it:

x:fieldmodifier="public" 

so code:

<canvas x:name="canvas" x:fieldmodifier="public" width="640" height="480" margin="667,10,5,289"/> 

now if have instance of mainwindow, access canvas.

non fancy way 2:

create public property in mainwindow.cs codebehind

public canvas canvas { { return cica; } } 

(maybe static if wanna dirty)


ps.: comments right. have problem design


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -