2010-03-12 5 views
1

나는 여러 번 조사했으나 이전에는 보지 못했습니다. 아마 정말 간단한 질문이지만 내 머리를 감쌀 수는 없습니다.XAML의 캔버스에 새로운 너비와 높이를 사용하십시오.

그리드를 동적으로 그리는 Excel 용 VSTO 추가 기능을 작성했습니다. 그런 다음 새 창을 시작하고 Canvas의 내용을 생성 된 Grid로 바꿉니다. 인쇄에 문제가 있습니다. print 프로 시저를 호출하면 그리드로 바꾸기 전에 이전 값인 canvas.height 및 canvas.width가 반환됩니다.

샘플 :

string="<Grid Name=\"CanvasGrid\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">..Lots of stuff..</Grid>"; 

// Launch new window and replace the Canvas element 

WpfUserControl newWindow = new WpfUserControl();        
newWindow.Show(); 


//To test 
MessageBox.Show(myCanvas.ActualWidth.ToString()); 
//return 894 
Grid testGrid = myCanvas.FindName("CanvasGrid") as Grid; 
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString()); 
//return 234 


StringReader stringReader = new StringReader(LssAllcChrt); 
XmlReader xmlReader = XmlReader.Create(stringReader); 

Canvas myCanvas = newWindow.FindName("GrphCnvs") as Canvas; 
myCanvas.Children.Clear(); 
myCanvas.Children.Add((UIElement)XamlReader.Load(xmlReader)); 

//To test 
MessageBox.Show(myCanvas.ActualWidth.ToString()); 
//return 894 but should be much larger the Grid spans all three of my screens 
Grid testGrid = myCanvas.FindName("CanvasGrid") as Grid; 
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString()); 
//return 234 but should be much larger the Grid spans all three of my screens 

//Run code from WpfUserControl.cs after it loads from button click 
Grid testGrid = canvas.FindName("CanvasGrid") as Grid; 
MessageBox.Show("Grid " + testGrid.ActualWidth.ToString()); 
//return 234 but should be much larger the Grid spans all three of my screens 

그래서 기본적으로 나는 나의 새로운 폭과 높이가 무엇인지 말하는 방법이 없습니다.

+0

에 대한

덕분에, 당신은 편집기에서 101,010 버튼을 사용하여 코드로 블록을 포맷 할 수 있습니다. – itowlson

+0

'Grid'는 전체'Canvas'를 사용합니까? 'Grid'에서 신뢰할 수있는 크기를 얻을 수 있습니까? – Jay

+0

초기 그리드는 전체 캔버스를 차지하지 않지만 생성 된 그리드는 전체 캔버스를 차지할 수도 있고 그렇지 않을 수도 있습니다. 흥미로운 점은 Canvas를 Grid 차원에 바인딩하는 방법은 무엇입니까? 현재 Canvas는 창과 함께 확장 및 축소됩니다. –

답변

0

여기에 내가 문제를 해결하기 위해 수행 한 작업이 있습니다.

기본적으로 시각적 인 본드를 벗어난 경우 그리드를 인쇄하려고했습니다. 나는 새 요구 사항 (Yeah me (sarcasm))이기 때문에 새 창을 TabControl 및 TabItems로 변경했습니다. 그래서 내가 한 것은 TabItem의 유일한 컨텐츠로에서 ScrollViewer를 참조 선택한 TabItem의를 참조이었고, FrameworkElement으로 그리드 참조 :

TabItem ti = GBtabControl.SelectedItem as TabItem; 
ScrollViewer sc = ti.Content as ScrollViewer; 
FrameworkElement element = sc.Content as FrameworkElement; 

요소는 정확한 폭과 높이를주고 내가 지금 인쇄 할 수 있으며, 차트를 png 파일로 내 보냅니다. 팁으로 지원

관련 문제