I have a grid with a templatecolumn which holds a checkbox. I'm using a templatecolumn because I don't have any properties on my binded object to use and I'm getting the rules for the checkbox outside the binded object.
I have already resolved how to get data for the row whenever user clicks the checkbox but now I need to check the checkboxes based on the outside rules. I've done this so far that I have the row where I need to check the checkbox but how can I get the checkbox control from the row? Like I said the checkbox is in a templatecolumn.
Any ideas?
I've taken another approach with this. I used my own column instead of TemplateColumn and created my own ContentProvider. With this I can command the checkbox there is still one problem.
I'm using a list of selected values to check if the item is selected (= checkbox is checked). How can I pass that list to the custom ContentProvider? I need some access to that list object.
Hi,
There isn't a need to create your own column. Instead simply use a binding on the checkbox to your data object, and use a valueconverter to manipulate the data to get your value.
<DataTemplate><CheckBox IsChecked="{Binding Converter={StaticResource myConverter}}"/>
</DataTemplate>
-SteveZ
Ok, that sounds like it could work also but the problem I had with the ContentProvider still remains. I need access to this list object of selected values and I need it also in the Converter?
Where is the list object coming from?
Does it have a relation with the row's data? Or is this list on the application level and completely separate from your data?
MyValueConverter is an IValueConverter which can convert your data pretty much any way you want. You can read more about IValueConverters from here: http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(VS.95).aspx and from here: http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx
I'm not sure what you exactly want to do with your list of ints but hope this helps.
hi,
what is MyValueConverter , i have list of int. and i want to assign to textblock. how can i do that
Thanks,
Nandu
in that case, you define your converter in the code behind and pass in your list into it.
public Page2()
{
MyValueConverter mvc = new MyValueConverter(myList);
this.Resources.Add("mvc", mvc);
InitializeComponent();
}
<ig:TemplateColumn Key="Name">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name, Converter={StaticResource mvc}}"/>
</ig:TemplateColumn.ItemTemplate>
</ig:TemplateColumn>
Now, you'll have access to your list, and you use that to update your data.
The list object has no relation to the row data and is completely separate from it. I was thinking that maybe I could pass it on to the converter by using converterparameter? Any other ideas?