c# - WPF data binding to dictionary with enum key -
c# - WPF data binding to dictionary with enum key -
i have solution couple of projects. in 1 project, model has enum called modelenum.
then in wpf project have viewmodel has dictionary.
and in viewmodel have valuesdictionary setup as:
private dictionary<modelenum, string> _valuesdictionary = new dictionary<modelenum, string>(); public dictionary<modelenum, string> valuesdictionary { { homecoming _valuesdictionary; } set { _valuesdictionary = value; onpropertychanged(_valuesdictionary); } }
in xaml have:
xmlns:model="clr-namespace:model.data;assembly=model" ... <textbox text="{binding path=valuesdictionary[(model:modelenum)modelenum.enum1].value}" horizontalalignment="left" height="29" margin="90,82,0,0" textwrapping="wrap" verticalalignment="top" width="50"/>
the next xaml snippet:
(model:modelenum)modelenum.enum1
is giving me error "parameter type mismatch." i'm confused because thought casting enum type expecting. referenced this question seek no luck.
replace
(model:modelenum)modelenum.enum1].value
with
(model:modelenum)enum1]
then try. hope work.
c# wpf xaml dictionary enums
Comments
Post a Comment