Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Styles, Setters and DataBinding
5 replies. Latest Post by squallgmn on April 8, 2009.
(0)
jpeters
Member
3 points
25 Posts
10-23-2008 12:46 PM |
I am trying to create a style for a control and use some databinding... Here is a sample:
Howerver, I am getting XAML parse exceptions (AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR ) when I attempt to use this:
<Style TargetType="TextBox" x:Key="blah" >
This works fine in WPF -- is there any similar mechanism in Silverlight?
gabouy
219 points
45 Posts
10-23-2008 1:11 PM |
Looks like it's not supported/buggy, I've tried something similar with the same result. If I set the textbox value directly with the binding expression it works.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
10-27-2008 4:37 AM |
Hello, data binding can only be used on FrameworkElements. Setter is not a FrameworkElement.
WadeFlex...
377 points
82 Posts
10-27-2008 5:23 AM |
So, one way to think about the setters is similar to a css file. It is specify the look, style of a control that is defined or it defines an animation action based on the Target Type.
Now if you want to define the data layout structure for a data grid then you will want to look at Data Templates. Again it is very similar to the data templates from asp.net.
(Please mark this as Answered if it helps!)
squallgmn
4 points
2 Posts
04-08-2009 10:01 AM |
Yi-Lun Luo - MSFT: Hello, data binding can only be used on FrameworkElements. Setter is not a FrameworkElement.
Seems odd that the same syntax works fine in WPF and not in Silverlight. Why would MSFT take away such a critical feature?
04-08-2009 10:57 AM |
I have a similar issue with using setters with databinding. I am using the Silverlight Toolkit's Tree control. Supposedly I am supposed to be able to track the IsSelected property of a TreeViewItem as follows:
<Controls:TreeView x:Name="FlowTree" ItemsSource="{Binding Path=SomeNodes}"> <Controls:TreeView.ItemContainerStyle> <Style TargetType="Controls:TreeViewItem"> <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=OneWay}" /> </Style> </Controls:TreeView.ItemContainerStyle> <Controls:TreeView.ItemTemplate> <Windows:HierarchicalDataTemplate ItemsSource="{Binding Path=ChildNodes}" > ... </Windows1:HierarchicalDataTemplate> </Controls:TreeView.ItemTemplate> </Controls:TreeView>
<Controls:TreeView.ItemTemplate>
</Windows1:HierarchicalDataTemplate>
This works fine in WPF. However, I get the same error as the previous posters when I attempt this same technique in Silverlight. How then am I supposed to bind the IsSelected property of my databound items to the tree nodes?