Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The issue seems to be <a href="http://www.simple-talk.com/dotnet/.net-framework/data-and-silverlight-2-data-binding/" rel="nofollow noreferrer">Rule #1 from this post</a>:</p> <blockquote> <p>The target of data binding must be a FrameworkElement.</p> </blockquote> <p>So since ScaleTransform isn't a FrameworkElement it doesn't support binding. I tried to bind to a SolidColorBrush to test this out and got the same error as with the ScaleTransform. </p> <p>So in order to get around this you can create a control that exposes a dependency property of your tag data type. Then have a property changed event that binds the properties of your tag data to the properties in the control (one of which would be the scale transform). Here is the code I used to test this out.</p> <p>items control:</p> <pre><code>&lt;ItemsControl x:Name="items"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;local:TagControl TagData="{Binding}" /&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre> <p>tag control xaml:</p> <pre><code>&lt;UserControl x:Class="SilverlightTesting.TagControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt; &lt;TextBlock x:Name="text" TextWrapping="Wrap" FontSize="18" Margin="4,4,4,4"&gt; &lt;TextBlock.RenderTransform&gt; &lt;ScaleTransform x:Name="scaleTx" /&gt; &lt;/TextBlock.RenderTransform&gt; &lt;/TextBlock&gt; &lt;/UserControl&gt; </code></pre> <p>tag control code:</p> <pre><code>public partial class TagControl : UserControl { public TagControl() { InitializeComponent(); } public Tag TagData { get { return (Tag)GetValue(TagDataProperty); } set { SetValue(TagDataProperty, value); } } // Using a DependencyProperty as the backing store for TagData. This enables animation, styling, binding, etc... public static readonly DependencyProperty TagDataProperty = DependencyProperty.Register("TagData", typeof(Tag), typeof(TagControl), new PropertyMetadata(new PropertyChangedCallback(TagControl.OnTagDataPropertyChanged))); public static void OnTagDataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var tc = obj as TagControl; if (tc != null) tc.UpdateTagData(); } public void UpdateTagData() { text.Text = TagData.Title; scaleTx.ScaleX = scaleTx.ScaleY = TagData.Weight; this.InvalidateMeasure(); } } </code></pre> <p>Seems like overkill for just setting a single property, but I couldn't find an easier way. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload