c# - using a converter while reading xaml from string using XamlReader.Parse() -
i trying load xaml using xamlreader.parse() , code:
<helpers:filterdatagrid xmlns:helpers="clr-namespace:urm.helpers;assembly=urm" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:grid="clr-namespace:microsoft.windows.controls;assembly=wpftoolkit" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:convert="clr-namespace:urm.converters;assembly=urm" itemssource ="{binding pendingcontracts}" autogeneratecolumns="false" margin="20,0,10,0" height ="auto" width ="auto"> <helpers:filterdatagrid.resources> <convert:dateconverter x:key="dateconverter"/> </helpers:filterdatagrid.resources> <helpers:filterdatagrid.columns> <grid:datagridtextcolumn header="contract id" binding="{binding contractid}" /> <grid:datagridtextcolumn header="date submitted" binding="{binding datesubmitted, {staticresource dateconverter}}" /> <grid:datagridtextcolumn header="submitted by" binding="{binding submitted_by}" /> <grid:datagridtextcolumn header="company name" binding="{binding proprietors_company_name}" /> <grid:datagridtextcolumn header="term of contract" binding="{binding termofcontact}" /> </helpers:filterdatagrid.columns> </helpers:filterdatagrid>
how add converter. have added namespace converter keep getting error:
'cannot create unknown type '{clr-namespace:urm.converters;assembly=urm}dateconverter'.'
i added same manner added other namespaces work well.
edit: parse code
private void initialize() { using (var sp = new silentpartnerdatacontext()) { try { pendingcontracts = new observablecollection<salescontract>(getallcontracts()); string data = sp.xamlexpressions.single(c => c.usercontrolname == "pendingcontracts").xamltext; contractcontent = xamlreader.parse(data) frameworkelement; } catch(exception) { messagebox.show("unable show data"); } } }
make sure dateconverter class public:
public class dateconverter : ivalueconverter { ... }
Comments
Post a Comment