c# - WPF Access Self -
this first day wpf. fun!
i have wpf application opens/returns file openfiledialog
. have existing script deconstructs , extracts info already. need able access info (i guess bind to) , display in element in xaml. haven't been able figure out how this.
so setup.
mainwindow.xaml.cs:
namespace gridview { public partial class mainwindow { private gridset<byte> _grids; public mainwindow() { initializecomponent(); } private void open_onclick(object sender, routedeventargs e) { var opendialog = new openfiledialog(); if (opendialog.showdialog().value) { //populate _grids info } } } }
mainwindow.xaml:
<window 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" mc:ignorable="d" x:class="gridview.mainwindow" title="grid view" width="800" height="600" windowstartuplocation="centerscreen"> <dockpanel> ... "open_onclick" here ... <textbox/> </dockpanel> </window>
as can see, .cs file interaction logic mainwindow
. why on earth can't figure out how configure textbox display info in _grids
?
i have fiddled x:name
, x:reference
, window.resources
, datacontext
, binding
, , on, haven't found guide yet has applied this. , it's because still don't understand every facet of wpf. doing wrong here?
(i alternatively satisfied wpf tutorial doesn't create brain ooze out ears.)
you have declared _grids
in c#, it's not added visual tree.
the simplest way declare object in xaml (though i'm not 100% sure gridset
- can't find documentation on that). if simple grid
you'd have:
<dockpanel> <grid x:name="mygrid" /> </dockpanel>
by naming can access in code:
mygrid.children.add(something);
to utilize binding must set datacontext
of window. simplest way have:
this.datacontext = this;
in constructor.
c# wpf xaml
No comments:
Post a Comment