![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |