Hi,
I would like to add a custom view to my xamDataPresenter in order to display images in a WrapPanel.
So, I think that I must implement my own View (from ViewBase), but can you help me to acheive this ?
I have try, but the Records are not wrapped !
My XAML :
<vov:WrapView x:Key="ThumbnailsView"> </vov:WrapView>
Here is the class I use :
public class WrapView : Infragistics.Windows.DataPresenter.ViewBase { protected override CellPresentation CellPresentation { get { return CellPresentation.CardView; } } protected override FieldLayoutTemplateGenerator GetFieldLayoutTemplateGenerator(FieldLayout fieldLayout) { return new CardViewFieldLayoutTemplateGenerator(fieldLayout); } protected override bool HasLogicalOrientation { get { return true; } } protected override Type ItemsPanelType { get { return typeof(WrapPanel); } } // protected override Type RecordPresenterContainerType //{ // get // { // return base.RecordPresenterContainerType; // } //} protected override bool IsNestedPanelsSupported { get { return true; } } protected override bool IsFixedRecordsSupported { get { return true; } } }
I'm trying this... without success... now I provide extent and viewport !
Here is the code I use :
sealed public class AnimatedWrapPanel : WrapPanel, IScrollInfo { #region Variables private ScrollViewer _owner; private bool _canHScroll = false; private bool _canVScroll = false; private Point _offset; private Size _extent = new Size(0, 0); private Size _viewport = new Size(0, 0); private TranslateTransform _trans = new TranslateTransform(); #endregion #region Constructor public AnimatedWrapPanel() { this.RenderTransform = _trans; } #endregion #region MeasureOverride protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint) { ScrollContentPresenter scp = Infragistics.Windows.Utilities.GetAncestorFromType(this, typeof(ScrollContentPresenter), false) as ScrollContentPresenter; return base.MeasureOverride(new Size(scp.ActualWidth, scp.ActualHeight)); } #endregion #region IScrollInfo public ScrollViewer ScrollOwner { get { return _owner; } set { _owner = value; } } public bool CanHorizontallyScroll { get { return _canHScroll; } set { _canHScroll = value; } } public bool CanVerticallyScroll { get { return _canVScroll; } set { _canVScroll = value; } } public double HorizontalOffset { get { return _offset.X; } } public double VerticalOffset { get { return _offset.Y; } } public double ExtentHeight { get { return _extent.Height; } } public double ExtentWidth { get { return _extent.Width; } } public double ViewportHeight { get { return _viewport.Height; } } public double ViewportWidth { get { return _viewport.Width; } } public void LineUp() { SetVerticalOffset(this.VerticalOffset - 1); } public void LineDown() { SetVerticalOffset(this.VerticalOffset + 1); } public void SetVerticalOffset(double offset) { if (offset < 0 || _viewport.Height >= _extent.Height) offset = 0; else if (offset + _viewport.Height >= _extent.Height) offset = _extent.Height - _viewport.Height; _offset.Y = offset; if (_owner != null) _owner.InvalidateScrollInfo(); _trans.Y = -offset; } public void LineLeft() { throw new Exception("The method or operation is not implemented."); } public void LineRight() { throw new Exception("The method or operation is not implemented."); } public Rect MakeVisible(Visual visual, Rect rectangle) { for (int i = 0; i < this.InternalChildren.Count; i++) { if ((Visual)this.InternalChildren == visual) { // we found the visual! Let's scroll it into view. First we need to know how big // each child is. Size finalSize = this.RenderSize; Size childSize = new Size( finalSize.Width, (finalSize.Height * 2) / this.InternalChildren.Count); // now we can calculate the vertical offset that we need and set it SetVerticalOffset(childSize.Height * i); // child size is always smaller than viewport, because that is what makes the Panel // an AnnoyingPanel. return rectangle; } } //throw new ArgumentException("Given visual is not in this Panel"); return rectangle; } public void MouseWheelUp() { SetVerticalOffset(this.VerticalOffset - 10); } public void MouseWheelDown() { SetVerticalOffset(this.VerticalOffset + 10); } public void MouseWheelLeft() { throw new Exception("The method or operation is not implemented."); } public void MouseWheelRight() { throw new Exception("The method or operation is not implemented."); } public void PageUp() { double childHeight = (_viewport.Height * 2) / this.InternalChildren.Count; SetVerticalOffset(this.VerticalOffset - childHeight); } public void PageDown() { double childHeight = (_viewport.Height * 2) / this.InternalChildren.Count; SetVerticalOffset(this.VerticalOffset + childHeight); } public void PageLeft() { throw new Exception("The method or operation is not implemented."); } public void PageRight() { throw new Exception("The method or operation is not implemented."); } public void SetHorizontalOffset(double offset) { throw new Exception("The method or operation is not implemented."); } //protected override Size MeasureOverride(Size availableSize) //{ // Size childSize = new Size( // availableSize.Width, // (availableSize.Height * 2) / this.InternalChildren.Count); // Size extent = new Size( // availableSize.Width, // childSize.Height * this.InternalChildren.Count); // if (extent != _extent) // { // _extent = extent; // if (_owner != null) // _owner.InvalidateScrollInfo(); // } // if (availableSize != _viewport) // { // _viewport = availableSize; // if (_owner != null) // _owner.InvalidateScrollInfo(); // } // foreach (UIElement child in this.InternalChildren) // child.Measure(childSize); // return availableSize; //} //protected override Size ArrangeOverride(Size finalSize) //{ // Size childSize = new Size( // finalSize.Width, // (finalSize.Height * 2) / this.InternalChildren.Count); // Size extent = new Size( // finalSize.Width, // childSize.Height * this.InternalChildren.Count); // if (extent != _extent) // { // _extent = extent; // if (_owner != null) // _owner.InvalidateScrollInfo(); // } // if (finalSize != _viewport) // { // _viewport = finalSize; // if (_owner != null) // _owner.InvalidateScrollInfo(); // } // for (int i = 0; i < this.InternalChildren.Count; i++) // this.InternalChildren.Arrange(new Rect(0, childSize.Height * i, childSize.Width, childSize.Height)); // return finalSize; //} #endregion }
_canHScroll and _canVScroll are FALSE by default.
And when should I call InvalidateScrollInfo ?
Ok, I will try... maybe I have a solution.
So, now I have "boxes" with the datas.... I would like to set a custom template for the content.
I would like an image and a text below, something like this
<Border StrokeThickness="2"> <Grid> <Image Source="{TemplateBinding Content.MyIcon}"/> <TextBlock Text="{TemplateBinding Content.MyIcon}" Grid.Row="1"/> </Grid></Border>How can I do ?
Do you have any solution for this problem ?
Thanks
Can someone help us ?
I does find any solution
It should be possible !
Please help....
Hi Joe,
I have try several combinations, but none work :-(
How can I access the DataRecord through binding, I have try {Binding Title} and some others, but no data is displayed !
You're right, thanks.
I have do what you say and it is better, but it sounds that having
<ContentPresenter x:Name="PART_RecordContentSite"/>
is mandatory, or it crash !
What I want :
- Display an image binded to a property of my datasource, say "CoverImage"
- a title binded to the "Title" property
- I must be able to double click on the title and rename it, like for GridView
Do you have an idea on how I can acheive this ?