Skip to main content

Microsoft Silverlight

Unanswered Question Dynamic DataTemplate!RSS Feed

(0)

jimijani1982
jimijani...

Member

Member

3 points

8 Posts

Dynamic DataTemplate!

i am making an application with mvvm architecture. i have a view which consist of a list( of borders which inturn contains textblock). i need to template the contents of the list based on contents of the textblock , i.e if the text property of TextBlock contains a substring = "system" , i want the Border's background to be red . how can i do this . thanks Jamal.

Martin Kruszynski
Martin K...

Member

Member

15 points

27 Posts

Re: Dynamic DataTemplate!

You can make ItemTemplate with a custom control with some visual states. The control has f.e Text property which you bind (control would contain TextBlock in its template which you could bind to your control Text property). When binding value has changed, you change control visual state (in callback of dependency property TextProperty of your control).

If you have complex conditions (f.e contains), you probably should write code in your control. If you have to display different views for different data values in a simple way, you can use DataStateBehavior or DataStateSwitchBehavior from http://expressionblend.codeplex.com/

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities