Note that there are some explanatory texts on larger screens.

plurals
  1. POdatabinding on a user control only working partially (silverlight)
    primarykey
    data
    text
    <p>I am not sure what I am doing wrong here. I spent a good hour last night to figure it out, maybe I am just dumb.</p> <p>I created this user control to display a bordered text, which uses data binding to fill the style and the text.</p> <p>This is how I call it from the main page:</p> <pre><code>&lt;mynamespace:BorderedText x:Name="DateTime" Grid.Column="1" Grid.Row="0" BorderStyle="{StaticResource borderStyle}" LabelStyle="{StaticResource labelStyle}" TextStyle="{StaticResource valueStyle}" Label="Current Date/Time" Text="N/A" /&gt; </code></pre> <p>The control is pretty simple:</p> <pre><code>&lt;UserControl x:Class="MyNamespace.BorderedText" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="480"&gt; &lt;Grid&gt; &lt;Border Name="border" Style="{Binding BorderStyle}"&gt; &lt;StackPanel&gt; &lt;TextBlock Style="{Binding LabelStyle}" Text="{Binding Label}" /&gt; &lt;TextBlock Style="{Binding TextStyle}" Text="{Binding Text}" /&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>The problem is that all data binding works, except for the Border data binding. I also tried to data bind the background or any other property, without success. Code behind has the DependencyProperty properties set up and that’s it. Note that the DataContext for data binding is set up in the constructor. Tried to assign it to the Grid or to the Border itself, without success. Does anybody have any clue or see something big I am missing here?</p> <pre><code>namespace MyNamespace { public partial class BorderedText : UserControl { public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(BorderedText), new PropertyMetadata(null)); public static readonly DependencyProperty LabelStyleProperty = DependencyProperty.Register("LabelStyle", typeof(Style), typeof(BorderedText), new PropertyMetadata(null)); public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(BorderedText), new PropertyMetadata(null)); public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register("TextStyle", typeof(Style), typeof(BorderedText), new PropertyMetadata(null)); public static readonly DependencyProperty BorderStyleProperty = DependencyProperty.Register("BorderStyle", typeof(Style), typeof(BorderedText), new PropertyMetadata(null)); public BorderedText() { InitializeComponent(); ((Grid)this.Content).DataContext = this; //((Border)this.Content).DataContext = this; } public string Label { set { SetValue(LabelProperty, value); } get { return (string)GetValue(LabelProperty); } } public Style LabelStyle { set { SetValue(LabelStyleProperty, value); } get { return (Style)GetValue(LabelStyleProperty); } } public string Text { set { SetValue(TextProperty, value); } get { return (string)GetValue(TextProperty); } } public Style TextStyle { set { SetValue(TextStyleProperty, value); } get { return (Style)GetValue(TextStyleProperty); } } public Style BorderStyle { set { SetValue(BorderStyleProperty, value); } get { return (Style)GetValue(BorderStyleProperty); } } } } </code></pre> <p>---- UPDATE:</p> <p>It turned out to be something completely different and unrelated to databinding which is properly wired...</p> <p>In the borderStyle I was using this syntax for a background property:</p> <pre><code> &lt;Setter Property="Background"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush&gt; &lt;SolidColorBrush.Color&gt; &lt;Color&gt; &lt;Color.A&gt; 100 &lt;/Color.A&gt; &lt;Color.R&gt;#95&lt;/Color.R&gt; &lt;Color.B&gt;#ED&lt;/Color.B&gt; &lt;/Color&gt; &lt;/SolidColorBrush.Color&gt; &lt;/SolidColorBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; </code></pre> <p>which apparently works in the designer but not in the phone. Changing it to:</p> <pre><code> &lt;Setter Property="Background"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush Color="#649500ED" /&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; </code></pre> <p>Solved the problem</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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