I have a form, it has a grid.
I autogenerate the columns and tweak them as required:
if (e.PropertyName == "id")
{
System.Windows.Style style = new Style(typeof(DataGridCell));
style.Setters.Add(new Setter(DataGridCell.ContentTemplateProperty, CreateBtnTemplate(30)));
e.Column.CellStyle = style;
}
private static DataTemplate CreateBtnTemplate(int width)
{
string str = "<DataTemplate xmlns='http://schemas.microsoft.com/client/2007' >"
//+ "<Button Tag='{Binding id}' Content='Respond'
+ "<Button Tag='{Binding id}' Content='Respond' "
+ "Visibility='{Binding id, Converter={StaticResource myConverter}}'"
+ " />"
+ "</DataTemplate>";
return (DataTemplate)XamlReader.Load(str);
}
In my pages xaml, I have:
<Grid x:Name="LayoutRoot" Margin="0,0,4,0">
<Grid.Resources>
<my:EnableDisableConverter x:Name="myConverter" x:Key="myConverter"></my:EnableDisableConverter>
</Grid.Resources>
My class looks like:
public class EnableDisableConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Service1failedbackups f = value as Service1failedbackups;
if (f.resolution == null || f.resolution == "")
return System.Windows.Visibility.Visible;
else
return System.Windows.Visibility.Collapsed;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ return null;
}
}
In short, if the content of "resolution" is blank, I want a button so I it can be filled in, via a popup window.
Now, it all compiles, it all looks good. (my is defined as
xmlns:my="clr-namespace:SilverlightApplication1"
as part of the page header.
The error I get is:
Error: Unhandled Error in Silverlight Application
Code: 2272
Category: ParserError
Message: Cannot find a Resource with the Name/Key myConverter
File:
Line: 1
Position: 121
Now, its all OK until I put the visibility part of my btnTemplate in. I've used the ID column specifically because, I dont need users to see it.
Please, can someone tell me what I missed. This is driving me nuts.
I fixed it
Heres how.
in my xaml file I added
and then under grid I added
I then ditched all the auto generating of my columns and set
NOW it works. NOW it flipping works.. hurrah