首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

WPF中下列代码中运行出来滚动条如何不出来,求大神解答,多谢

2013-12-11 
WPF中下列代码中运行出来滚动条怎么不出来,求大神解答,谢谢!前台代码,NamecanGroupInfoContent的Canvas里

WPF中下列代码中运行出来滚动条怎么不出来,求大神解答,谢谢!
前台代码,Name=canGroupInfoContent的Canvas里面的内容是动态添加的,为什么超过好多了还不显示?
<Grid Width="494">
        <Border  BorderThickness="1" BorderBrush="LightBlue">
            <!--Height="279" Width="494"-->
            <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
                <Canvas>
                    <Canvas Height="26" Name="canGroupInfoHeader" Background="LightGray" Width="494" VerticalAlignment="Top" MouseLeftButtonUp="Canvas_MouseLeftButtonUp">
                        <Label Content="+  图组信息" Height="26" HorizontalAlignment="Left" Margin="10,0,0,0" Name="lbGroupInfo" VerticalAlignment="Top" />
                    </Canvas>
                    <Canvas Canvas.Top="26" Visibility="Hidden" Name="canGroupInfoContent">
                        <Border Width="128" Height="24">
                            <TextBox IsReadOnly="True" Text="图组名" TextAlignment="Center"  />
                        </Border>
                        <Border Canvas.Left="128" Width="366" Height="24">
                            <TextBox Text=""  />
                        </Border>
                        <Border Canvas.Top="24" Width="128" Height="24">
                            <TextBox IsReadOnly="True" Text="图组名" TextAlignment="Center"  />
                        </Border>
                        <Border Canvas.Top="24" Canvas.Left="128" Width="366" Height="24">
                            <TextBox Text=""  />
                        </Border>
                    </Canvas>
                    <Canvas Height="26" Width="494" Name="canFileInfoHeader"  Background="LightGray" Canvas.Top="26" MouseLeftButtonUp="Canvas_MouseLeftButtonUp">
                        <Label Content="+  文件信息" Height="26" HorizontalAlignment="Left" Margin="10,0,0,0" Name="lbFileInfo" VerticalAlignment="Top" />
                    </Canvas>
                    <Canvas Canvas.Top="52" Name="canFileInfoContent" Visibility="Hidden"></Canvas>
                </Canvas>
            </ScrollViewer>
        </Border>
    </Grid>

后台代码:

double top = 0;
        private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Canvas can = sender as Canvas;
            if (can != null)


            {
                switch (can.Name)
                {
                    case "canGroupInfoHeader":
                        if (canGroupInfoContent.Visibility == System.Windows.Visibility.Hidden)
                        {
                            canGroupInfoContent.Visibility = System.Windows.Visibility.Visible;
                            lbGroupInfo.Content = "-  基本信息";
                            XmlDocument xmlDoc = new XmlDocument();
                            string strPath = System.Environment.CurrentDirectory;
                            string xmlPath = System.IO.Path.Combine(strPath, @"XML\WordCoding.xml");
                            if (File.Exists(xmlPath) == false)
                            {
                                MessageBox.Show("没有找到配置文件请检查!", "系统提示");
                                return;
                            }
                            xmlDoc.Load(xmlPath);
                            XmlNodeList InforMation = xmlDoc.DocumentElement.SelectNodes("Information/basic");
                            foreach (XmlNode info in InforMation)
                            {
                                Border border = new Border();
                                border.Width = 128;
                                border.Height = 24;
                                //border.SetValue(Canvas.LeftProperty, 128);
                                border.SetValue(Canvas.TopProperty, top);
                                TextBox textbox = new TextBox();
                                textbox.IsReadOnly = true;
                                textbox.Text = info.Attributes["name"].Value;
                                textbox.TextAlignment = TextAlignment.Center;


                                border.Child = textbox;
                                Border border1 = new Border();
                                border1.Width = 366;
                                border1.Height = 24;
                                border1.SetValue(Canvas.LeftProperty, (double)128);
                                border1.SetValue(Canvas.TopProperty, top);
                                TextBox textbox1 = new TextBox();
                                // textbox1.Name = info.Attributes["value"].Value.ToString();
                                border1.Child = textbox1;
                                canGroupInfoContent.Children.Add(border);
                                canGroupInfoContent.Children.Add(border1);
                                top = top + 24;
                            }
                            canFileInfoHeader.SetValue(Canvas.TopProperty, top);
                            //ScrollViewer.SetHorizontalScrollBarVisibility(Orientation.Vertical,ScrollBarVisibility.Visible);
                        }
                        else
                        {
                            canGroupInfoContent.Visibility = System.Windows.Visibility.Hidden;
                            lbGroupInfo.Content = "+  基本信息";
                            canFileInfoHeader.SetValue(Canvas.TopProperty, (double)26);
                            top = 0;
                        }
                        break;
                    case "canFileInfoHeader":
                        if (canFileInfoContent.Visibility == System.Windows.Visibility.Hidden)
                        {
                            canFileInfoContent.Visibility = System.Windows.Visibility.Visible;
                            lbFileInfo.Content = "-  文件详细信息";


                            XmlDocument xmlDoc = new XmlDocument();
                            string strPath = System.Environment.CurrentDirectory;
                            string xmlPath = System.IO.Path.Combine(strPath, @"XML\WordCoding.xml");
                            if (File.Exists(xmlPath) == false)
                            {
                                MessageBox.Show("没有找到配置文件请检查!", "系统提示");
                                return;
                            }
                            xmlDoc.Load(xmlPath);
                            XmlNodeList InforMation = xmlDoc.DocumentElement.SelectNodes("Information/FileBasic");
                            double top = 0;
                            foreach (XmlNode info in InforMation)
                            {
                                Border border = new Border();
                                border.Width = 128;
                                border.Height = 24;
                                //border.SetValue(Canvas.LeftProperty, 128);
                                border.SetValue(Canvas.TopProperty, top);
                                TextBox textbox = new TextBox();
                                textbox.IsReadOnly = true;
                                textbox.Text = info.Attributes["name"].Value;
                                textbox.TextAlignment = TextAlignment.Center;
                                border.Child = textbox;

                                Border border1 = new Border();
                                border1.Width = 366;
                                border1.Height = 24;
                                border1.SetValue(Canvas.LeftProperty, (double)128);


                                border1.SetValue(Canvas.TopProperty, top);
                                TextBox textbox1 = new TextBox();
                                // textbox1.Name = info.Attributes["value"].Value.ToString();
                                border1.Child = textbox1;
                                canFileInfoContent.Children.Add(border);
                                canFileInfoContent.Children.Add(border1);
                                top = top + 24;
                            }
                            //canFileInfoHeader.SetValue(Canvas.TopProperty, top);
                            //canFileInfoHeader.SetValue(Canvas.TopProperty, (double)(26 + 48));
                        }
                        else
                        {
                            canFileInfoContent.Visibility = System.Windows.Visibility.Hidden;
                            lbFileInfo.Content = "+  文件详细信息";
                            //canFileInfoHeader.SetValue(Canvas.TopProperty, (double)26);
                        }
                        break;
                }
            }
[解决办法]
第一层的Canvas需要设置高度或最小高度。

热点排行