Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Problem with autosizing content when working at DrawingVisual level

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-17-2006   #1 (permalink)
John Dunn
Guest


 

Problem with autosizing content when working at DrawingVisual level

I'm having problems with getting my content to size correctly. I'm
trying to implement what are effectively 'popup' windows using WPF. The
These windows are implemented with a grid which contains a canvas. The
canvases size is variable and MeasureOverride is implemented to return
the size of the canvas.

One this which complicates this is that the owner canvas of the popups
implements it's own VisualCollection so items are manually added to the
VisualCollection.

I can't get the popup window grid to resize so it's content is visible.
The only way I can get the popup to display at all is by calling
popup.Arrange(). The width and height passed into Arrange are basically
dummy values but they seem to be sticking.

Any help would be appreciated-

John

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Input;

namespace scroll
{

public class content_t : Canvas
{
public content_t()
{
Background = Brushes.LightBlue;
}
// this returns the requested size of the content
protected override Size MeasureOverride( Size sz ) {
return new Size( 200, 200 );
}
}

public class popup_t : Grid
{
public popup_t(String title)
{
this.ClipToBounds = true;
Background = Brushes.Transparent;
// one column
ColumnDefinitions.Add( new ColumnDefinition() );
// 2 rows
RowDefinitions.Add( new RowDefinition() );
RowDefinitions.Add( new RowDefinition() );
RowDefinitions[0].Height = new GridLength(18);
// background
System.Windows.Shapes.Rectangle rc = new
System.Windows.Shapes.Rectangle();
rc.Fill = Brushes.Gray;
rc.Stroke = Brushes.Gray;
rc.RadiusX = 3;
rc.RadiusY = 3;
SetColumnSpan( rc, 2 );
SetRowSpan( rc, 2 );
Children.Add( rc );
// title bar
TextBlock tb = new TextBlock();
tb.Text = title;
tb.Foreground = Brushes.DarkGray;
tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
tb.Margin = new Thickness( 3, 3, 3, 0 );
SetRow( tb, 0 );
SetColumn( tb, 0 );
Children.Add( tb );
// create content
content_t content = new content_t();
SetRow(content, 1);
SetColumn(content, 0);
Children.Add(content);
content.Margin = new Thickness(3, 0, 3, 3);
}
}
public class canvas_t : Canvas
{
private VisualCollection _children;
public canvas_t()
{
_children = new VisualCollection(this);
Background = Brushes.AntiqueWhite;
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
// create a window
Point pt = e.GetPosition( this );
popup_t popup = new popup_t("title");
_children.Add(popup);

popup.Arrange(new Rect(pt.X, pt.Y, 100, 100 ));
}
protected override int VisualChildrenCount
{
get { return _children.Count; }
}
// Provide a required override for the GetVisualChild method.
protected override Visual GetVisualChild(int index)
{
if (index < 0 || index > _children.Count)
{
throw new ArgumentOutOfRangeException();
}
return (Visual)_children[index];
}
}

public class app_t : Application
{
Window win;
protected override void OnStartup(StartupEventArgs e)
{
win = new Window();
win.Title = "popup";
win.Content = new canvas_t();
win.Show();
base.OnStartup(e);
}
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
app_t app = new app_t();
app.Run();
}
}
}

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
windows dreamscene content not working Billenium Vista General 3 09-03-2008 10:09 PM
stackpanel is and autosizing a ListBox Lloyd Dupont Avalon 2 06-13-2007 01:55 AM
Loading an XAML file into a DrawingVisual John Dunn Avalon 3 06-22-2006 11:29 AM
Lots of DrawingVisual items in a UIElement questions John Dunn Avalon 1 06-15-2006 12:41 PM
Weirdness with get-content | replace | set-content - file content is deleted!! Andrew Watt [MVP] PowerShell 4 05-23-2006 05:59 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51