Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to bind collection to custom control in wpf
    primarykey
    data
    text
    <p>I am building a custom control and I want to pass a collection to it so that control display that collection, my code is as the following :</p> <pre><code>&lt;gm:Calendar SubscriptionSource="{Binding Subscriptions}"&gt;&lt;/gm:Calendar&gt; </code></pre> <p>and in Custom control "Calendar" </p> <pre><code>public static readonly DependencyProperty SubscriptionSourceProperty = DependencyProperty.Register( "SubscriptionSource", typeof(ObservableCollection&lt;Subscription&gt;), typeof(Calendar), new FrameworkPropertyMetadata(new ObservableCollection&lt;Subscription&gt;())); public ObservableCollection&lt;Subscription&gt; SubscriptionSource { get { return (ObservableCollection&lt;Subscription&gt;)GetValue(SubscriptionSourceProperty); } set { SetValue(SubscriptionSourceProperty, value); } } </code></pre> <p>I use in generic.xaml</p> <pre><code>&lt;ItemsControl ItemsSource="{Binding SubscriptionSource}"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;!--Box--&gt; &lt;Border BorderBrush="Black" BorderThickness="1" Padding="0"&gt; &lt;Border Name="InnerBorder" BorderBrush="{Binding Path=Day, Converter={StaticResource DayBorderColorConverter}}" BorderThickness="2"&gt; &lt;Border.Style&gt; &lt;Style TargetType="{x:Type Border}"&gt; &lt;Style.Triggers&gt; &lt;!--Current Day--&gt; &lt;DataTrigger Binding="{Binding IsToday}" Value="true"&gt; &lt;Setter Property="Border.Background"&gt; &lt;Setter.Value&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#FF1EA6C8" Offset="0"/&gt; &lt;GradientStop Color="#FF0691B3" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Border.Style&gt; &lt;DockPanel&gt; &lt;!--Day Number--&gt; &lt;StackPanel Orientation="Horizontal" DockPanel.Dock="Top" FlowDirection="RightToLeft"&gt; &lt;TextBlock TextAlignment="Right" Text="{Binding Day.Date, Converter={StaticResource DateConverter}, ConverterParameter=DAY}" FontSize="12" Margin="5,5,5,5" &gt; &lt;TextBlock.Style&gt; &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding IsTargetMonth}" Value="false"&gt; &lt;Setter Property="TextBlock.Foreground" Value="Gray"&gt;&lt;/Setter&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/TextBlock.Style&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;CheckBox IsEnabled="{Binding IsEnabled}" Style="{StaticResource DiscreteCheckBoxStyle}" /&gt; &lt;/DockPanel&gt; &lt;/Border&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;UniformGrid Rows="6" Columns="7" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;/ItemsControl&gt; </code></pre> <p>I want to Bind Subscriptions observable collection to the calendar custom control so I can use the collection in the custom control, is there is away to do this?</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.
 

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