added samples
[windows-sources.git] / sdk / samples / WPFSamples / ScrollViewerScrollChanged / cpp / scrollviewer_code.cpp
blob6e0f34802c81f1bd84474c2fc315ace637d26363
1 //ScrollViewer_Code.cpp file
3 using namespace System;
4 using namespace System::Windows;
5 using namespace System::Windows::Controls;
6 using namespace System::Windows::Media;
7 using namespace System::Windows::Shapes;
8 using namespace System::Threading;
10 namespace ScrollViewer_Sample {
12 public ref class app : Application {
14 private:
15 Rectangle^ rect1;
16 ScrollViewer^ scrView1;
17 StackPanel^ sPanel;
18 Window^ mainWindow;
19 TextBlock^ txt1;
20 TextBlock^ txt2;
22 protected:
23 virtual void OnStartup (StartupEventArgs^ e) override
25 Application::OnStartup(e);
26 CreateAndShowMainWindow();
29 public:
30 void sChanged (System::Object^ sender, ScrollChangedEventArgs^ e)
32 txt1->Text = "ScrollViewer.HorizontalScrollBarVisibility is set to: " + scrView1->ComputedHorizontalScrollBarVisibility.ToString();
33 txt2->Text = "ScrollViewer.VerticalScrollBarVisibility is set to: " + scrView1->ComputedVerticalScrollBarVisibility.ToString();
36 public:
37 void CreateAndShowMainWindow ()
39 // Create the application's main window
40 mainWindow = gcnew Window();
41 mainWindow->Height = 400;
42 mainWindow->Width = 400;
45 // Create a ScrollViewer
46 scrView1 = gcnew ScrollViewer();
47 txt1 = gcnew TextBlock();
48 txt2 = gcnew TextBlock();
49 scrView1->CanContentScroll = true;
50 scrView1->HorizontalScrollBarVisibility = ScrollBarVisibility::Auto;
51 scrView1->VerticalScrollBarVisibility = ScrollBarVisibility::Auto;
53 // Create a StackPanel
54 sPanel = gcnew StackPanel();
55 sPanel->Orientation = Orientation::Vertical;
56 sPanel->Children->Add(txt1);
57 sPanel->Children->Add(txt2);
59 // Add the first rectangle to the StackPanel
60 rect1 = gcnew Rectangle();
61 rect1->Stroke = Brushes::Black;
62 rect1->Fill = Brushes::SkyBlue;
63 rect1->Height = 400;
64 rect1->Width = 400;
65 sPanel->Children->Add(rect1);
67 scrView1->ScrollChanged += gcnew ScrollChangedEventHandler(this,&ScrollViewer_Sample::app::sChanged);
68 scrView1->Content = sPanel;
69 mainWindow->Content = scrView1;
70 mainWindow->Title = "ScrollViewer Sample";
71 mainWindow->Show();
77 private ref class EntryClass sealed {
79 public:
80 [System::STAThread()]
81 static void Main ()
83 ScrollViewer_Sample::app^ app = gcnew ScrollViewer_Sample::app();
84 app->Run();
89 //Entry Point:
90 [System::STAThreadAttribute()]
91 void main ()
93 return ScrollViewer_Sample::EntryClass::Main();