i'm trying style of wpf chart rectangles. i'm using mvvm, , need rectangles uniformly sized. when defined via xaml, works fixed "bucketcount" of 4:
<visualbrush> <visualbrush.visual> <uniformgrid height="500" width="500" rows="1" columns="{binding bucketcount}"> <rectangle grid.row="0" grid.column="0" fill="#22add8e6" /> <rectangle grid.row="0" grid.column="1" fill="#22d3d3d3"/> <rectangle grid.row="0" grid.column="2" fill="#22add8e6"/> <rectangle grid.row="0" grid.column="3" fill="#22d3d3d3"/> </uniformgrid> </visualbrush.visual> <visualbrush>
how can bind observablecollection of rectangles? there no "itemssource" property on uniformgrid. need use itemscontrol? if so, how can this?
thanks in advance.
you use itemscontrol bind this. simple example itemssource observablecollection<brush>
<visualbrush> <visualbrush.visual> <itemscontrol x:name="itemscontrol" itemssource="{binding mybrushes}"> <itemscontrol.itemspanel> <itemspaneltemplate> <uniformgrid height="500" width="500" rows="1"/> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate> <rectangle fill="{binding}"/> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> </visualbrush.visual> </visualbrush>
update
works usage scenario, might missing here. here's full code i've tried. same result both
mainwindow.xaml
<grid> <grid.background> <visualbrush> <visualbrush.visual> <itemscontrol x:name="itemscontrol" itemssource="{binding mybrushes}"> <itemscontrol.itemspanel> <itemspaneltemplate> <uniformgrid height="500" width="500" rows="1"/> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate> <rectangle fill="{binding}"/> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> <!--<uniformgrid height="500" width="500" rows="1" columns="4"> <rectangle grid.row="0" grid.column="0" fill="#22add8e6" /> <rectangle grid.row="0" grid.column="1" fill="#22d3d3d3"/> <rectangle grid.row="0" grid.column="2" fill="#22add8e6"/> <rectangle grid.row="0" grid.column="3" fill="#22d3d3d3"/> </uniformgrid>--> </visualbrush.visual> </visualbrush> </grid.background> </grid>
mainwindow.xaml.cs
public partial class mainwindow : window { public mainwindow() { initializecomponent(); brushconverter brushconverter = new brushconverter(); mybrushes = new observablecollection<brush>(); mybrushes.add(brushconverter.convertfrom("#22add8e6") brush); mybrushes.add(brushconverter.convertfrom("#22d3d3d3") brush); mybrushes.add(brushconverter.convertfrom("#22add8e6") brush); mybrushes.add(brushconverter.convertfrom("#22d3d3d3") brush); this.datacontext = this; } public observablecollection<brush> mybrushes { get; set; } }
Comments
Post a Comment