wpf - UniformGrid and ItemsSource -
i have uniformgrid
. inside, put grid
contains 2 children - , image
, canvas
. have list<grid>
member contains grid
definition.
i'm updating source of image
null
actual image, expecting image shown inside uniformgrid
, nothing happens.
here's code:
xaml:
<border grid.row="0" > <itemscontrol x:name="streamsitemscontrol" itemssource="{binding streams}"> <itemscontrol.itemspanel> <itemspaneltemplate> <uniformgrid x:name="streamsgrid" cliptobounds="true" height="300" /> </itemspaneltemplate> </itemscontrol.itemspanel> </itemscontrol> </border>
viewmodel:
private list<grid> m_streams = new list<grid>(); public list<grid> streams { { return m_streams; } set { m_streams = value; onpropertychanged("streams"); } }
edit: adding more code:
public struct streamcontainer { public string streamname; public grid streamgrid; public canvas streamcanvas; public image streamimage; } private readonly list<streamcontainer> m_streamscontainer = new list<streamcontainer>(); public sequencesplayerviewmodel() { registerstream("color"); registerstream("depth"); registerstream("ir"); registerstream("left"); } private void registerstream(string streamname) { streamcontainer streamcontainer; streamcontainer.streamname = streamname; streamcontainer.streamcanvas = new canvas { name = streamname + "canvas", background = brushes.transparent, verticalalignment = verticalalignment.top }; streamcontainer.streamimage = new image { name = streamname + "image", stretch = stretch.uniform, verticalalignment = verticalalignment.top }; var widthbinding = new binding { path = new propertypath("actualwidth") }; var heightbinding = new binding { path = new propertypath("actualheight"), source = streamcontainer.streamimage }; streamcontainer.streamcanvas.setbinding(frameworkelement.heightproperty, heightbinding); streamcontainer.streamcanvas.setbinding(frameworkelement.widthproperty, widthbinding); streamcontainer.streamgrid = new grid { name = streamname + "grid" }; streamcontainer.streamgrid.children.add(streamcontainer.streamimage); streamcontainer.streamgrid.children.add(streamcontainer.streamcanvas); streamcontainer.streamgrid.visibility = visibility.collapsed; m_streamscontainer.add(streamcontainer); } private void addstream(streamcontainer currentstream) { var listofstreams = getlistofstream(); if (listofstreams.count > 0) { var streamtoadd = listofstreams.find(currstream => currstream.name == currentstream.streamname); if (streamtoadd != null) if (!string.isnullorempty(currentstream.streamname)) { currentstream.streamgrid.visibility = visibility.visible; (currentstream.streamgrid.children[0] image).source = streamtoadd.imagebitmap; } } streams.add(currentstream.streamgrid); } private void onnewframeready(uint framenumber) { try { var listofstreams = getlistofstream(); foreach (var elem in streams) { var currentcanvas = (elem.children[1] canvas); var canvasname = currentcanvas.name.split(new[] { "canvas" }, stringsplitoptions.removeemptyentries).first(); var currentstream = listofstreams.find(currstream => currstream.name == canvasname); if (!string.isnullorempty(currentstream.name)) (elem.children[0] image).source = currentstream.imagebitmap; panel p = currentcanvas; elem.updatelayout(); elem.width = (elem.children[0] image).actualwidth; elem.height = (elem.children[0] image).actualheight; elem.updatelayout(); } } catch (exception ex) { } }
the viewmodel
connected correctly, , bindings
of other controls working properly.
i can see streams
member updated correctly, meaning image
correctly updated new source
.
what missing?
perhaps issue items not showing @ -- not image isn't updating (because see you're updating source property of image element directly)... list, propertychanged
event fire when list<>
changed, not when added it, unlike observablecollection<>
fires events when items added/removed/replaced/cleared.
try replacing list<>
observablecollection<>
(found in system.collections.objectmodel
)
other that, grid
, image
instead defined in datatemplate
within itemscontrol.itemtemplate
, source
bound property of stream viewmodel (which should have collection of) -- unrelated issue.
Comments
Post a Comment