Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo UserControls, one binds, one doesn't
    primarykey
    data
    text
    <p>I have two very simple UserControls in a simple WinRT demo project. No Viewmodel--mostly just colored boxes for layout exploration. The first UserControl I created works fine. The second, very similar one, won't bind to any properties--it shows up as blank.</p> <p>The first UserControl looks like this:</p> <pre><code> &lt;UserControl x:Class="Demo.SmallStartTile" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Demo" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="SmallStartTileUC" d:DesignHeight="300" d:DesignWidth="400"&gt; &lt;Grid x:Name="SmallTileGrid" Margin="0,0,8,8" Background="{Binding Background, ElementName=SmallStartTileUC}" &gt; &lt;Rectangle Stroke="{Binding BorderBrush, ElementName=SmallStartTileUC}" Grid.RowSpan="2" /&gt; &lt;TextBlock x:Name="SmallTileTitle" Text="{Binding TileText, ElementName=SmallStartTileUC}" Style="{StaticResource SmallTileHeader}"/&gt; &lt;Path x:Name="IconPath" Style="{StaticResource SmallTileIcon}" Data="{Binding TileIconPathData, ElementName=SmallStartTileUC}" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; namespace Demo { public sealed partial class SmallStartTile : UserControl { public static DependencyProperty TileTextProperty = DependencyProperty.Register("TileText", typeof(string), typeof(SmallStartTile), new PropertyMetadata("tile content")); public string TileText { get { return (string)GetValue(TileTextProperty); } set { SetValue(TileTextProperty, value); } } public static DependencyProperty TileIconPathDataProperty = DependencyProperty.Register("TileIconPathData", typeof(string), typeof(SmallStartTile), new PropertyMetadata("F0")); public string TileIconPathData { get { return (string)GetValue(TileIconPathDataProperty); } set { SetValue(TileIconPathDataProperty, value); } } public SmallStartTile() { this.InitializeComponent(); } } </code></pre> <p>}</p> <p>And the second one, which I made just like the first one by clicking Add New Item and picking UserControl in Blend:</p> <pre><code>&lt;UserControl x:Class="Demo.SmallMediaTile" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Demo" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="SmallMediaTileUC" d:DesignHeight="300" d:DesignWidth="400"&gt; &lt;Grid Margin="0,0,8,8" Background="{Binding Background, ElementName=SmallMediaTileUC}" &gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Rectangle Stroke="{Binding BorderBrush, ElementName=SmallMediaTileUC}" Grid.RowSpan="2" /&gt; &lt;Viewbox Margin="30" Child="{Binding Content, ElementName=SmallMediaTileUC}"&gt; &lt;/Viewbox&gt; &lt;TextBlock Grid.Row="1" Text="{Binding SourceText, ElementName=SmallMediaTileUC}" Style="{StaticResource SmallMusicTileHeader}"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; namespace Demo { public sealed partial class SmallMediaTile : UserControl { public static DependencyProperty SourceTextProperty = DependencyProperty.Register("SourceText", typeof(string), typeof(SmallMediaTile), new PropertyMetadata("source")); public string SourceText { get { return (string)GetValue(SourceTextProperty); } set { SetValue(SourceTextProperty, value); } } public SmallMediaTile() { this.InitializeComponent(); } } </code></pre> <p>}</p> <p>I use the UserControl in the main Page like this:</p> <pre><code> &lt;local:SmallMediaTile x:Name="Source1Tile" Grid.Column="0" Grid.Row="0" SourceText="Radio" Background="Blue" BorderBrush="Red"&gt; &lt;local:SmallMediaTile.Content&gt; &lt;Canvas x:Name="radio_icon" Height="68" Width="34"&gt; &lt;Path Data="F1M299.6182,396.2988C299.6182,389.7208,297.0722,383.5548,292.4572,378.8398L288.6162,382.6758C292.2022,386.3718,294.1842,391.1778,294.1842,396.2988C294.1842,401.4238,292.2022,406.2368,288.6162,409.9328L292.4572,413.7738C297.0722,409.0538,299.6182,402.8808,299.6182,396.2988" Fill="White" Height="34.934" Canvas.Left="0" Stretch="Fill" Canvas.Top="16.501" Width="11.002"/&gt; &lt;Path Data="F1M311.1738,396.2988C311.1738,386.6278,307.4348,377.5528,300.6788,370.6208L296.8258,374.4618C302.5658,380.3698,305.7398,388.0798,305.7398,396.2988C305.7398,404.5218,302.5658,412.2298,296.8258,418.1428L300.6788,421.9898C307.4348,415.0498,311.1738,405.9718,311.1738,396.2988" Fill="White" Height="51.369" Canvas.Left="8.21" Stretch="Fill" Canvas.Top="8.282" Width="14.348"/&gt; &lt;Path Data="F1M322.7578,396.2988C322.7578,383.5298,317.8508,371.5348,308.9638,362.3388L305.1168,366.1748C312.9758,374.3538,317.3338,384.9778,317.3338,396.2988C317.3338,407.6208,312.9758,418.2488,305.1168,426.4268L308.9638,430.2748C317.8508,421.0698,322.7578,409.0798,322.7578,396.2988" Fill="White" Height="67.936" Canvas.Left="16.501" Stretch="Fill" Canvas.Top="0" Width="17.641"/&gt; &lt;/Canvas&gt; &lt;/local:SmallMediaTile.Content&gt; &lt;/local:SmallMediaTile&gt; </code></pre> <p>The first one picks up all the properties and displays like I expect, but the second one only picks up the Viewbox content. I've looked through SO and been googling but can't figure out what the problem is. Sorry if this is longwinded.</p>
    singulars
    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.
 

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