logo
down
shadow

How to bind a Canvas to a collection of items in Silverlight


How to bind a Canvas to a collection of items in Silverlight

By : SHAWN barker
Date : November 22 2020, 07:01 PM
should help you out I know this question is a little old, but you can just use a render transform - I'm doing something similar;
code :


Share : facebook icon twitter icon
How to bind collection of collection to a datagrid in Silverlight 4

How to bind collection of collection to a datagrid in Silverlight 4


By : Timothy Kompanchenko
Date : March 29 2020, 07:55 AM
I hope this helps . I ended up using third party control, where they support binding collection of collection. Both Telerik and Component One grid control support binding this kind of collection.
Can't bind child collection in silverlight

Can't bind child collection in silverlight


By : user2282610
Date : March 29 2020, 07:55 AM
I hope this helps you . WCF RIA Services does not include child entities by default. I needed to put [Include()] on the OrderPayments property of the Order object. Works like a charm now.
Silverlight ListBox Items beeing displayed in a different order thant the Items collection

Silverlight ListBox Items beeing displayed in a different order thant the Items collection


By : GaneshRamK
Date : March 29 2020, 07:55 AM
around this issue Unless there is a specific reason, instead of trying to put the button into the listbox collection itself you would be best to create a new control with the button outside and below the listbox. You can always style the button to look as though it's within the listbox if required.
WPF/Silverlight Bind Canvas to Collection of View Model Elements

WPF/Silverlight Bind Canvas to Collection of View Model Elements


By : Dario Pizzio
Date : March 29 2020, 07:55 AM
will help you It's absolutely disgusting how much XAML this takes. I'll look for a way to clean it up using styles and templates. Also, I need to draw the line to the center of the point, that shouldn't be hard. For now, below is what worked. I ended up created a Collection> ViewModel to bind the "Line" collection. Otherwise I'm looking at the line point-by-point and can't draw a line since I can't find X2/Y2.
for the inspiration Alexander.
code :
  <ItemsControl ItemsSource="{Binding Lines}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate DataType="viewModels:LineViewModel">
                <ItemsControl ItemsSource="{Binding LineSegments}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <ItemsControl>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <Canvas />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl ItemsSource="{Binding Lines}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <Canvas />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Line X1="{Binding Item1.X}" X2="{Binding Item2.X}" Y1="{Binding Item1.Y}" Y2="{Binding Item2.Y}" Stroke="Black" StrokeThickness="2"/>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <ItemsControl ItemsSource="{Binding LineSegment}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <Canvas />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Ellipse Canvas.Left="{Binding X}" Canvas.Top="{Binding Y}" Width="10" Height="10" Fill="Black">
                                                <Ellipse.RenderTransform>
                                                    <TranslateTransform X="{Binding X}" Y="{Binding Y}"/>
                                                </Ellipse.RenderTransform>
                                            </Ellipse>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ItemsControl>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
namespace CanvasBindTest.ViewModels
{
    /// <summary>
    ///     Sample view model showing design-time resolution of data
    /// </summary>
    [ExportAsViewModel(typeof (MainViewModel))]
    public class MainViewModel : BaseViewModel
    {
        public MainViewModel()
        {
            var start = new PointViewModel {X = 0, Y = 0};
            var middle = new PointViewModel {X = 30, Y = 10};
            var end = new PointViewModel {X = 20, Y = 0};
            var simpleLine = new LineSegmentsViewModel(new[] {start, middle, end});
            Lines = new ObservableCollection<LineViewModel> {new LineViewModel(new[] {simpleLine})};
        }

        public ObservableCollection<LineViewModel> Lines { get; private set; }
    }

    public class LineViewModel : BaseViewModel
    {
        public LineViewModel(IEnumerable<LineSegmentsViewModel> lineSegments)
        {
            LineSegments = new ObservableCollection<LineSegmentsViewModel>(lineSegments);
        }

        public ObservableCollection<LineSegmentsViewModel> LineSegments { get; private set; }
    }

    public class LineSegmentsViewModel : BaseViewModel
    {
        public LineSegmentsViewModel(IEnumerable<PointViewModel> lineSegment)
        {
            LineSegment = new ObservableCollection<PointViewModel>(lineSegment);
            Lines = new Collection<Tuple<PointViewModel, PointViewModel>>();
            var tmp = lineSegment.ToArray();
            for (var i = 0; i < tmp.Length - 1; i++)
            {
                Lines.Add(new Tuple<PointViewModel, PointViewModel>(tmp[i], tmp[i+1]));
            }
        }

        public Collection<Tuple<PointViewModel, PointViewModel>> Lines { get; private set; }  

        public ObservableCollection<PointViewModel> LineSegment { get; private set; }
    }


    public class PointViewModel : BaseViewModel
    {
        private int x, y;

        public int X
        {
            get { return x; }
            set
            {
                x = value;
                RaisePropertyChanged(() => X);
            }
        }

        public int Y
        {
            get { return y; }
            set
            {
                y = value;
                RaisePropertyChanged(() => Y);
            }
        }
    }
}
Bind a Silverlight TabControl to a Collection

Bind a Silverlight TabControl to a Collection


By : Massinissa
Date : March 29 2020, 07:55 AM
wish helps you I have a Collection of Model-objects in my ViewModel. I would like to be able to bind a TabControl to these and use a DataTemplate to extract the information from the Model-objects. When I try to do this I get the errormessage: Unable to cast object of type Model to object of type TabItem. After spending some time looking for a solution I found the following: , Create converter
Related Posts Related Posts :
  • System.Windows.Ria.Controls and POCO
  • High density Silverlight charting control
  • How to map Stored Procedures with EF4?
  • VS2010 Code: 2104 Could not download the Silverlight application
  • MVVM Binding in Silverlight3 ItemsControl to get the parent controls DataContext
  • Why do Silverlight 4 Assemblys still have the version 2.0.5.0?
  • Cannot find System.Windows.Controls.dll for Silverlight 3
  • Binding List to DataGrid Silverlight
  • Block interaction temporarily ,during wcf call!
  • Use .net reactive in silverlight to generate multiple events
  • Diagramming in Silverlight MVVM- connecting shapes
  • how many concurrent user can login to silverlight application?
  • What are the security implications of making a clientaccesspolicy proxy workaround?
  • Silverlight: Why can't silverlight see my xaml file referenced in MergedDictionary?
  • Which Silverlight Control Set is better? Telerik or ComponentArt?
  • What is the best substitute for FlowDocument in Silverlight?
  • Silverlight Windows Phone 7: Load Images From URL
  • How can I determine in silverlight code where the silverlight instance is running?
  • Silverlight datagrid fails to display data
  • Out of browser silverlight application vs a traditional desktop application
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk