c# - Binding doesn't subscribe to PropertyChangedHandler -
alright i've been on ages , can't see why doesn't work.
i have binding usercontrol label onto property in class cell. class implements interface inotifypropertychanged. there everytime set method called call onpropertychanged("value)which expected update label it's binded to. not case.
i did research on stack clarify of problems i've checked:
i have datacontext set since use mvvm light set viewmodel locator.
this property outside of viewmodel it's suppose in order not make more expandable towards other sizes of sudoku.
edit: property changed fired handler null suspect it's not being subscribed to, hence title.
edit 2 code sudoku game grid of 3x3 grids of 3x3 hiarchy here outtergrid has innergrids , innergrids have cells thought better not include these codes since same.
snipit of datacontext declared mainwindow.window:
<window x:class="sudokuwpf.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:sudokuwpf" datacontext="{binding main, source={staticresource locator}}" title="sudokuwindow" height="350" width="525"> here code of cell class
public class cell : inotifypropertychanged { private int _value; public int value { { return _value; } set { _value = value; //content = _value; onpropertychanged("value"); } } public event propertychangedeventhandler propertychanged; [notifypropertychangedinvocator] protected virtual void onpropertychanged([callermembername] string propertyname = null) { var handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } } and binding in usercontrol
<usercontrol x:class="sudokuwpf.usercontrolsudoku" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:localcontrol="clr-namespace:sudokuwpf" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" horizontalalignment ="stretch" horizontalcontentalignment ="stretch" verticalalignment ="stretch" verticalcontentalignment ="stretch" foreground="white" width="{binding relativesource={relativesource self}, path=actualheight}"> <usercontrol.resources> <localcontrol:cell x:key="cell"></localcontrol:cell> <localcontrol:innergrid x:key="innergrid"></localcontrol:innergrid> <localcontrol:outergrid x:key="outergrid"></localcontrol:outergrid> <datatemplate x:key="celltemplate"> <border x:name="border" borderbrush="aliceblue" borderthickness="1"> <label content="{binding source={staticresource cell}, path=value, updatesourcetrigger=propertychanged}"></label> </border> </datatemplate> any appreciated.
alright after wrongfully eliminating datacontext out of problem turned out core of problem. binded datacontext outer grid object this:
<usercontrol x:class="sudokuwpf.usercontrolsudoku" 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" horizontalalignment ="stretch" horizontalcontentalignment ="stretch" verticalalignment ="stretch" verticalcontentalignment ="stretch" foreground="white" width="{binding relativesource={relativesource self}, path=actualheight}" datacontext="{binding source=outergrid}" > public outergrid outergrid = new outergrid(); public usercontrolsudoku() { initializecomponent(); mainlist.datacontext = outergrid; }
Comments
Post a Comment