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
{
16 ScrollViewer
^ scrView1
;
23 virtual void OnStartup (StartupEventArgs
^ e
) override
25 Application::OnStartup(e
);
26 CreateAndShowMainWindow();
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();
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
;
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";
77 private ref
class EntryClass sealed
{
83 ScrollViewer_Sample::app
^ app
= gcnew
ScrollViewer_Sample::app();
90 [System::STAThreadAttribute()]
93 return ScrollViewer_Sample::EntryClass::Main();