Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I bind to this custom dependency property?
    text
    copied!<p>I have a DependencyProperty in my custom UserControl that looks like this:</p> <pre><code>public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", typeof(int), typeof(CallBoard), new PropertyMetadata(150)); public int ColumnWidth { get { return (int)GetValue(ColumnWidthProperty); } set { SetValue(ColumnWidthProperty, value); } } </code></pre> <p>In Expression Blend 3, I have this:</p> <pre><code>&lt;UserControl 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" x:Class="SilverlightTest.CallBoard" d:DesignWidth="640" d:DesignHeight="480"&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate x:Key="EmployeeHeaderTemplate"&gt; &lt;TextBlock Text="{Binding Name}" TextAlignment="Center" FontWeight="Bold" FontSize="16"/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="CallListItemTemplate"&gt; &lt;StackPanel &gt; &lt;TextBlock Text="{Binding CustomerName}" FontWeight="Bold"/&gt; &lt;TextBlock Text="{Binding Details}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="CallListTemplate"&gt; &lt;ListBox ItemTemplate="{StaticResource CallListItemTemplate}" ItemsSource="{Binding Calls}"/&gt; &lt;/DataTemplate&gt; &lt;/UserControl.Resources&gt; &lt;StackPanel x:Name="stackPanel" DataContext="{Binding Source={StaticResource DummyDataSource}}"&gt; &lt;ItemsControl ItemsPanel="{StaticResource HorizontalItemsPanelTemplate}" ItemTemplate="{StaticResource EmployeeHeaderTemplate}" ItemsSource="{Binding}"/&gt; &lt;ItemsControl ItemsPanel="{StaticResource HorizontalItemsPanelTemplate}" ItemTemplate="{StaticResource CallListTemplate}" ItemsSource="{Binding}"/&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>Now, what I'd like to do is make the ColumnWidth dependency property control the width of the TextBlock in the EmployeeHeaderTemplate DataTemplate and the ListBox in the CallListTemplate DataTemplate. I know I can do this in C#, but I have a feeling it'd also be possible with pure XAML data-binding.</p> <p>But, being relatively new to Silverlight and Expression Blend 3, I'm not sure how to go about this. Any suggestions?</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