Hi,
I am using Silverlight 4 in C# with Infragistics' web client package. What I am trying to do is to create a control template for a cell's style in a XamGrid control. Inside the control template, there is a TextBlock control which is used to display the cell's value.
I have successfully adding a TextBlock in the control template. However, when I was trying to assign the cell's value to the Text property of the TextBlock control by setting Text={TemplateBinding Cell.Value}, I got an error saying Value was nout found. If I set Text={TemplateBinding Content}, there was nothing displayed in the TextBlock control.
I am wondering how to bind the Text property of the TextBlock control to the cell's value.
Thank you for your response.
Best,
Frank
Hi Frank,
What exactly are you trying to do?
Why aren't you using a TextColumn, or if you're trying to bind to custom values, why aren't you using a TemplateColumn or UnboundColumn?
-SteveZ
Hi Stephen,
Thank you for getting back to me so quickly.
I am working on a small project which allows a user to enter a number, say 5, in a text box, then a XamGrid will automatically create the entered number, 5, of columns. The header of the columns must be underlined, so must be the cells in the grid, and all of the texts have red foreground color and right text alignment.
When I tried to use TextColumn to implement this functionality (because it has TextBlockStyle, through which I can easily set the underline for the texts), I found that I must assign each text column a unique key, which represents a property of a data object that the grid is bound to. The first difficulty I encountered was that I couldn't fully define all data objects that could be used as the ItemSource since my application allows the user to enter any number he wants. So, I came up with a solution to this problem. I defined a data object with just one property, and when filling out the property of the data object, each value is separated by a delimiter. In the example above, when the user enters 5 in the text box, the grid should create 5 columns. Instead of having to define in advance a data object that has 5 properties and assign a value to each of these 5 properties, I just instantiate an instance of the data object that has only one property, combine the 5 values with 4 delimiter into a single string, and assign the string to the only property of the data object. Regarding displaying the data, I add 5 unbound columns to the grid, and add a value conver to each of them, which parses the string and displaying the corresponding part of the string. By doing so, the grid can display any number of columns without having to define unlimited number of data objects first.
However, by using the unbound columns, I can't have the text displayed underlined. So, I am thinking about designing a control template that has a TextBlock to display a cell's data and assign the control template to the unbound columns. By doing so, I expect I can set foreground, text alignment, and underline very easily.
The question is then, how can I get a cell's value and have it displayed in the Text property of the TextBlock?
I am new to everything from Silverlight to Infragistics' package. So, I welcome any suggestions to my delimma.
Thank you very much.
You can use the ItemTemplate property of the UnboundColumn.
The DataContext is of type: UnboundDataContext. You can read more about the ItemTemplate and how to use the DataContext in the following help article:
http://help.infragistics.com/NetAdvantage/Silverlight/2010.2/CLR4.0/?page=xamGrid_Unbound_Column.html
But basically, you'll want to have a DataTemplate that looks like:<DataTemplate> <TextBlock Text={Binding Value} Style="{StaticResource YourTBStyle}" /></DataTemplate>
Hope this helps,
Hello Steve,
I tried your solution and it works perfectly for me!!!
Thank you so much!!!
Is it possible to create an item template and apply it to a signle cell of a unbound column?
The goal is to have values in some cells underlined, instead of having all of them underlined.
Thank you.
You wouldn't create a separate ItemTemplate, instead you'd have one ItemTemplate, and use a ValueConverter and a Binding to the TextDecorations property of the TextBlock
So something like:
<TextBlock TextDecorations={Binding Converter={StaticResource yourConverter}}/>
Then in your converter, the value you'll receive will be your data object, which you can validate against, and return the property TextDecoration value.
Thank you for getting back to me. Yes, I was able to achieve what I wanted based on your suggestion!
Excellent!