xaml - How can I add a resource to a silverlight custom control? -


i trying trim selected value of silverlight custom control combobox. have found using ivalueconverter class should way go. create in library

public class stringtrimmer : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         return value.tostring().trim();     }      public object convertback(object value, type targettype, object parameter,         system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } 

this xaml combobox

<usercontrol x:class="silverlightcontrollibrary.silverlightcomboboxcontrol" 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" height="25" width="122"> <combobox height="23" horizontalalignment="left" verticalalignment="top" width="120"           margin="0,0,0,0" name="moduleidfiltercb"            itemssource="{binding path=screen.licensemoduleids, mode=twoway}"           displaymemberpath="licensemodulename"                 selecteditem="{binding screen.bufferprop, converter={staticresource stringtrimmer},mode=twoway}"           /> </usercontrol> 

except resource "stringtrimmer" selecteditem can't resolved. tried adding reference xaml , still didnt work.

xmlns:c="clr-namespace:silverlightcontrollibrary" 

edit: tried this

xmlns:custom="clr-namespace:silverlightcontrollibrary" 

along with

selecteditem="{binding screen.bufferprop, converter= {staticresource custom:stringtrimmer}, mode=twoway}" 

to no avail..

this http://msdn.microsoft.com/en-us/library/cc189061%28v=vs.95%29.aspx microsof has xaml namespaces

and http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.convert.aspx ivalueconverter

where going wrong?

you have add static resource (usercontrol.resources section) reference converter e.g.:

<usercontrol      x:class="silverlightcontrollibrary.silverlightcomboboxcontrol"     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"      height="25"      width="122"     xmlns:custom="clr-namespace:silverlightcontrollibrary">  <usercontrol.resources>    <custom:stringtrimmer x:key="stringtrimmer" /> </usercontrol.resources>  <combobox height="23"            horizontalalignment="left"            verticalalignment="top"            width="120"           margin="0,0,0,0"            name="moduleidfiltercb"            itemssource="{binding path=screen.licensemoduleids, mode=twoway}"           displaymemberpath="licensemodulename"                 selecteditem="{binding screen.bufferprop, converter={staticresource stringtrimmer}, mode=twoway}" /> </usercontrol> 

for xaml reference can use name in x:key attribute, not "stringtrimmer".


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -