logo
down
shadow

How to use Canvas as the ItemsPanel for an ItemsControl in Silverlight 3


How to use Canvas as the ItemsPanel for an ItemsControl in Silverlight 3

By : user3851796
Date : October 15 2020, 11:12 PM
seems to work fine I'm not sure if it will work in your scenario, but I've accomplished this in the past using the RenderTransform.
code :


Share : facebook icon twitter icon
When using ItemsControl ItemsControl.ItemsPanel is set to Canvas, ContenPresenter comes in and break my Canvas propertie

When using ItemsControl ItemsControl.ItemsPanel is set to Canvas, ContenPresenter comes in and break my Canvas propertie


By : chris
Date : March 29 2020, 07:55 AM
it should still fix some issue there are several solutions coming to my mind:
use a layout/rendertransform instead of the attached property use margin instead of the attached property derive from ItemsControl, and override the behavior how the child containers are generated. (GetContainerForItemOverride, IsItemItsOwnContainerOverride). This article is explaining quite nicely how it works: http://drwpf.com/blog/2008/07/20/itemscontrol-g-is-for-generator/
ItemsControl, ItemsPanel and ItemsPresenter (Silverlight, XAML)

ItemsControl, ItemsPanel and ItemsPresenter (Silverlight, XAML)


By : Kay Byun
Date : March 29 2020, 07:55 AM
I wish this helpful for you ItemsControl is conceptually a control that houses items. Try to simply think of this control as a holder for zero or more objects.
ItemsPresenter is a bit tougher to explain, but this is part of the ItemsControl template that will define where the items are placed within it. Your ItemsControl's template can be anything you like, say a Grid with some pretty pictures around it, inside this template, you would place the ItemsPresenter where ever you want your items to be, say right in the middle of your grid. (this example is taken from msdn and simplified for ease of reading)
code :
<Style TargetType="HeaderedItemsControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
          <Grid>
            <Rectangle Stroke="Black" Fill="Red"/>
            <ItemsPresenter Margin="2,0,0,0"/>
          </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
Binding Canvas X,Y when used as ItemsControl ItemsPanel

Binding Canvas X,Y when used as ItemsControl ItemsPanel


By : LDAC
Date : March 29 2020, 07:55 AM
I wish this help you I encountered the same issue but solved it using a TriggerAction instead. You can use the System.Windows.Interactivity if you have the Blend SDK. The dll is located in
code :
c:\Program Files\Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\
System.Windows.Interactivity.dll`
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <Ellipse Stroke="Red" Width="2" Height="2">
            <ia:Interaction.Triggers>
                <ia:EventTrigger EventName="Loaded">
                    <tr:SetCanvasPropertiesAction Left="{Binding X}" Top="{Binding Y}" />
                </ia:EventTrigger>
            </ia:Interaction.Triggers>
        </Ellipse>
    </DataTemplate>
</ItemsControl.ItemTemplate>
xmlns:ia="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows.Media;

namespace Presentation.Triggers {
    public class SetCanvasPropertiesAction : TriggerAction<DependencyObject> {
        public static readonly DependencyProperty LeftProperty =
            DependencyProperty.Register("Left", typeof(double), typeof(SetCanvasPropertiesAction), new PropertyMetadata(default(double)));

        public static readonly DependencyProperty TopProperty =
            DependencyProperty.Register("Top", typeof(double), typeof(SetCanvasPropertiesAction), new PropertyMetadata(default(double)));

        public double Top {
            get { return (double)GetValue(TopProperty); }
            set { SetValue(TopProperty, value); }
        }

        public double Left {
            get { return (double)GetValue(LeftProperty); }
            set { SetValue(LeftProperty, value); }
        }

        protected override void Invoke(object parameter) {
            UIElement presenter = (UIElement)VisualTreeHelper.GetParent(AssociatedObject);
            Canvas.SetLeft(presenter, Left);
            Canvas.SetTop(presenter, Top);
        }
    }
}
Using a ScrollViewer with an ItemsControl with a Canvas as the ItemsPanel

Using a ScrollViewer with an ItemsControl with a Canvas as the ItemsPanel


By : YHJ
Date : March 29 2020, 07:55 AM
help you fix your problem The canvas's width/height when not explicitly set, will inherit from the ItemsControl. The "dynamic sizing" behavior you're expecting isn't how panels sizing and layout works out of the box.
You options are to:
Using a Grid as the ItemsPanel for an ItemsControl in Silverlight 3

Using a Grid as the ItemsPanel for an ItemsControl in Silverlight 3


By : Jai Ho
Date : October 15 2020, 01:19 AM
This might help you What you have won't work because Silverlight wraps each item -- each instance of the DataTemplate -- in a ListBoxItem, and the Grid.Column and Grid.Row attached properties need to be applied to that ListBoxItem, not to the TextBox that becomes the content of that ListBoxItem.
The good news is that you can set attributes on the implicit ListBoxItem using ListBox.ItemContainerStyle.
Related Posts Related Posts :
  • Difference between styles and control templates
  • Why can't I bind my Silverlight Button Click to a Prism DelegateCommand
  • Firefox selecting whole silverlight area causing browser scroll bars to become enabled
  • Switching to silverlight for enterprise application?
  • How to use binding to bind to the grand-parent element in Silverlight?
  • Dynamically set the Popup position/placement
  • What is the (best) short name for a Silverlight Application?
  • Silverlight clientaccesspolicy.xml bug? or design?
  • How to implement a single business logic layer based on CSLA and consume it from WPF, Winform and Silverlight?
  • How to close popup in silverlight?
  • Using a Grid as the ItemsPanel for an ItemsControl in Silverlight 3
  • Calling Begin/EndInvoke on Action and Func in Silverlight
  • Silverlight MVVM framework with navigation
  • What is the best menu metaphor for silverlight line-of-business apps?
  • Any reason not to check "application library caching" and "GPU acceleration" in silverlight apps?
  • Silverlight - Bing Maps - Customize Pushpin Style
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org