wpf - Why does my Rectangle's Fill not update when the GradientStops within the Brush change? -
i'm trying make gradient editor in wpf. this, i'm using gradientstopcollection datacontext rectangle (to display gradient) , itemscontrol (to display controls editing stops).
<window x:class="my.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" height="350" width="525"> <stackpanel> <stackpanel.datacontext> <gradientstopcollection> <gradientstop color="black" offset=".25"/> <gradientstop color="white" offset=".75"/> </gradientstopcollection> </stackpanel.datacontext> <rectangle height="100"> <rectangle.fill> <lineargradientbrush gradientstops="{binding}"/> </rectangle.fill> </rectangle> <itemscontrol itemssource="{binding}"> <itemscontrol.itemtemplate> <datatemplate> <slider maximum="1" value="{binding offset}"/> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> </stackpanel> </window>
when run app , move lower slider, snoop tells me rectangle.fill.gradientstops[1].offset has changed. however, rectangle's gradient appears have not changed reflect gradientstop's new offset.
aren't bindings supposed make rectangle update automatically? how can rectangle's fill update without needing create new set of gradientstops every time user touches slider?
gradientbrushes
don't automatically re-render when parts of stops change. if gradientstops
property changed brush update. rather trying build , reuse single brush binding parts may better off using imultivalueconverter
multibinding
build complete brush 2 slider values apply fill
property.