Skip to main content

Microsoft Silverlight

Answered Question Styles, Setters and DataBindingRSS Feed

(0)

jpeters
jpeters

Member

Member

3 points

25 Posts

Styles, Setters and DataBinding

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" >

<Setter Property="Text" Value="{Binding Mode=OneWay}" />

</Style>

This works fine in WPF -- is there any similar mechanism in Silverlight?

 

gabouy
gabouy

Member

Member

219 points

45 Posts

Re: Styles, Setters and DataBinding

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.

<Style TargetType="lTextBox" x:Key="blah">

<Setter Property="Text" Value="{Binding Company, Mode=TwoWay, Source={StaticResource data}}"/>

</Style>

 

(please mark as answer if this post answered your question)

Gabriel

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Styles, Setters and DataBinding

Hello, data binding can only be used on FrameworkElements. Setter is not a FrameworkElement.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

WadeFlextronics
WadeFlex...

Member

Member

377 points

82 Posts

Answered Question

Re: Styles, Setters and DataBinding

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!)  Cool

(Please mark as Answered if this helps!) Cool

Thanks,
Wade

squallgmn
squallgmn

Member

Member

4 points

2 Posts

Re: Styles, Setters and DataBinding

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?

squallgmn
squallgmn

Member

Member

4 points

2 Posts

Re: Styles, Setters and DataBinding

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>

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?

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities