Ejemplo n.º 1
0
        /// <summary>
        /// Set the SourceViewer for the current sample.
        /// </summary>
        /// <param name="viewer">The SourceViewer.</param>
        /// <remarks>
        /// This is called by the SourceViewer when loaded as a way to notify
        /// the browser that it has source without resorting to walking the
        /// visual tree, etc.
        /// </remarks>
        public void SetSourceViewer(SourceViewer viewer)
        {
            // Clean up the source viewer components
            if (SourceList != null)
            {
                SourceList.Items.Clear();
            }
            if (SourceText != null)
            {
                SourceText.Text = string.Empty;
            }

            // Set up the components
            if (viewer == null)
            {
                SourceExpander.Visibility     = Visibility.Collapsed;
                SampleGridSplitter.Visibility = Visibility.Collapsed;
                ExpandSampleDisplayArea();
            }
            else
            {
                if (SourceList != null)
                {
                    SourceExpander.Visibility     = Visibility.Visible;
                    SampleGridSplitter.Visibility = Visibility.Visible;

                    // Populate the source files
                    foreach (SourceFile file in viewer.Files)
                    {
                        string     name      = Path.GetFileName(file.Path);
                        string     extention = Path.GetExtension(file.Path);
                        StackPanel menuItem  = new StackPanel();

                        if (extention.Equals(".cs"))
                        {
                            menuItem = CreateMenuItem("cslogo.png", name);
                        }
                        else if (extention.Equals(".vb"))
                        {
                            menuItem = CreateMenuItem("vblogo.png", name);
                        }
                        else if (extention.Equals(".xaml"))
                        {
                            menuItem = CreateMenuItem("xamllogo.png", name);
                        }
                        SourceList.Items.Add(new ListBoxItem {
                            Content = menuItem, Tag = file
                        });
                    }

                    if (IsSourceViewCollapsed)
                    {
                        ExpandSampleDisplayArea();
                    }
                    else
                    {
                        ExpandSourceViewerArea();
                        Show(SourceList);
                    }

                    if (SourceList.Items.Count > 0)
                    {
                        SourceList.SelectedIndex = 0;
                    }
                }
            }
        }
        /// <summary>
        /// Set the SourceViewer for the current sample.
        /// </summary>
        /// <param name="viewer">The SourceViewer.</param>
        /// <remarks>
        /// This is called by the SourceViewer when loaded as a way to notify
        /// the browser that it has source without resorting to walking the
        /// visual tree, etc.
        /// </remarks>
        public void SetSourceViewer(SourceViewer viewer)
        {
            // Clean up the source viewer components
            if (SourceList != null)
            {
                SourceList.Items.Clear();
            }
            if (SourceText != null)
            {
                SourceText.Text = string.Empty;
            }

            // Set up the components
            if (viewer == null)
            {
                SourceExpander.Visibility = Visibility.Collapsed;
                SampleGridSplitter.Visibility = Visibility.Collapsed;
                ExpandSampleDisplayArea();
            }
            else
            {
                if (SourceList != null)
                {
                    SourceExpander.Visibility = Visibility.Visible;
                    SampleGridSplitter.Visibility = Visibility.Visible;

                    // Populate the source files
                    foreach (SourceFile file in viewer.Files)
                    {
                        string name = Path.GetFileName(file.Path);
                        string extention = Path.GetExtension(file.Path);
                        StackPanel menuItem = new StackPanel();

                        if (extention.Equals(".cs"))
                        {
                            menuItem = CreateMenuItem("cslogo.png", name);
                        }
                        else if (extention.Equals(".vb"))
                        {
                            menuItem = CreateMenuItem("vblogo.png", name);
                        }
                        else if (extention.Equals(".xaml"))
                        {
                            menuItem = CreateMenuItem("xamllogo.png", name);
                        }
                        SourceList.Items.Add(new ListBoxItem { Content = menuItem, Tag = file });
                    }

                    if (IsSourceViewCollapsed)
                    {
                        ExpandSampleDisplayArea();
                    }
                    else
                    {
                        ExpandSourceViewerArea();
                        Show(SourceList);
                    }

                    if (SourceList.Items.Count > 0)
                    {
                        SourceList.SelectedIndex = 0;
                    }
                }
            }
        }