Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Problem with autosizing content when working at DrawingVisual level

 
 
Old 11-17-2006   #1 (permalink)
John Dunn


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
Internet Explorer Content Advisor - Change Ratings Level Tutorials
Weirdness with get-content | replace | set-content - file content is deleted!! PowerShell


Vista Forums 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 Ltd

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