# Visual Studio Projects

The built-in designer can be used for editing simple layout files. Advanced users can use Visual Studio (available in the free Community edition) to create a project that has many advantages:

* Styles&#x20;
  * E.g. colors and fonts can be defined in an additional resource style file and be changed globally
  * Common place to put reusable items
* Designer
  * Layouts can be designed both visually and in code, which provides much more flexibility
* Bindings
  * WPF (and therefore ScreensPro) work a lot with bindings. Bindings can be used to bind an element's property to another settings
  * E.g. a HTTP JSON source can be defined and an element's Text property can be bound to a property of the JSON file

## Video Tutorial

{% embed url="<https://youtu.be/2sW44HOB-3k>" %}
Video demonstrating the required steps
{% endembed %}

## Install Visual Studio

* Download Visual Studio Community from [visualstudio.com](http://www.visualstudio.com)&#x20;
* Select *.NET Desktop Development* in the *Workloads* tab to be installed

## Create Advanced Project in ScreensPro

Create a new project folder, e.g. *AdvancedProject\_400x300* (it is best practice to include the resolution into the folder name for clarity)

In ScreensProServer, click *Config* - *New Config* and name the new config *AdvancedProject\_400x300* and place it in the newly created folder:

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2FJrjvSnpMK6YwxiuT8sLO%2Fimage.png?alt=media&#x26;token=87eaf00c-eba2-4115-b0bc-65b614418005" alt="" width="563"><figcaption></figcaption></figure>

Leave the *Working Directory* empty to indicate that the project files are in the same directory as the config file. Set the dimensions to 0 0 400 300 to indicate a position the top left corner:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2FWrKyPcQtGDpFvgpT5zpm%2Fimage.png?alt=media&#x26;token=f10ad58b-7a7c-4b63-a4c4-16fd522734b5" alt="" width="563"><figcaption></figcaption></figure>

## Creating the Project in Visual Studio

Open Visual Studio and click *Create a new project*. Select *WPF Class Library* in the next dialog. Name the Project *AdvancedProject\_400x300* and make sure to have the checkbox for *Place solution and project in the same directory* ticked. Also make sure that the project is created inside our newly created folder, this may mean to adjust the location accordingly:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2Fe8DsSLv2SaRvgf5zpl5k%2Fimage.png?alt=media&#x26;token=567f0ced-cbf3-4b7f-a392-b4bddfd53b48" alt="" width="563"><figcaption></figcaption></figure>

Select *.NET 9 (Standard Term Support)* in the next dialog and click Create.&#x20;

Visual Studio will now look something like this:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2FuF7Cauz3DeaAF72lDSiA%2Fimage.png?alt=media&#x26;token=f4a16c21-3aab-4e37-a0eb-d451ee85c386" alt="" width="563"><figcaption></figcaption></figure>

In order to use special controls for ScreensPro (e.g. RuntimeElement or TextElement), we need to include the ScreensPro.Controls nuget package from the internet. Right-Click on the project name and then  *Manage Nuget-Packages...* In the newly opened view, select *Browse* tab and enter *ScreensPro.Controls* in the *search* text box:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2F3kRzMZaaTeA1kCA1fRjL%2Fimage.png?alt=media&#x26;token=f86a86be-f2e0-4032-b174-3b68b2a3bc6a" alt="" width="563"><figcaption></figcaption></figure>

Click on it and click *Install* on the right-hand side - followed by some *Accept* clicks.&#x20;

Now we are done and can use this project.

## Bringing custom controls to Toolbox

If you do not see the ScreensPro controls in the Toolbox view, you have make them available first.

First build your project by right-click on the project and then select *Build*.&#x20;

In the Toolbox view right-click on an ampty area and click *Chose Items...* . In the *WPF Components* tab click *Browse*.&#x20;

<kbd>Not working like this.,</kbd>

## Designing Layouts in Visual Studio

### Clock Layout

Now we are ready to create our first layout: Right-Click on the project and select *Add* and then *User Control (WPF)* - this will a bring up a new dialog asking fo a name. We want ot start with a layout showing the current clock, therefore we name it *ClockLayout*:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2F4YDBNhSCUfzGeQ3aJPXm%2Fimage.png?alt=media&#x26;token=7cf75db8-8105-487d-a064-e08b565cead5" alt="" width="563"><figcaption></figcaption></figure>

First we need to tell Visual Studio about our custom user controls. Add a new line (attribute) in the `UserControls`  attributes list: \
`xmlns:controls="clr-namespace:Screens.Controls;assembly=Screens.Controls"`

Then you can add a clock element into the `Grid` content: \
`<controls:ClockElement Foreground="White"></controls:ClockElement>`

Ater that, you will be able to see a preview:<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2FFRaqjDT4AZZtpXGTvSOi%2Fimage.png?alt=media&#x26;token=703866b2-ba6c-4f07-8c88-79084a3a15de" alt="" width="563"><figcaption></figcaption></figure>

### Text Layout

Next we want ot add a text layout. Again we add a new WPF User Control as seen in the previous section, name it *FreetextLayout.xaml*.

Also register the custom controls again as in the previous section.

Then add a TextEelement control into the grid and name it x:Name="TextElement": `<controls:TextElement x:Name="TextElement" Foreground="White"></controls:TextElement>`

We are now ready to create the ScreensProClient for remoting.&#x20;

## Create Client config

In order to be able to show these layouts, we need a client configuration.&#x20;

Open ScreensPro Client application and click on the config toolbar - New Config: Place it in the newly created folder and name it AdvancedProject\_400x300 and click Save.<br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2Fu1cyvwJuVKE8Uk1ZuYTg%2Fimage.png?alt=media&#x26;token=de9d898b-2e84-403f-a8b7-806fba6663b4" alt="" width="563"><figcaption></figcaption></figure>

In the layout tab add the following layouts:&#x20;

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2Fdy8wmvCE26DdlMSHVSxG%2Fimage.png?alt=media&#x26;token=52832ec9-c9dc-4646-a8f2-7b86c242e1c8" alt="" width="563"><figcaption></figcaption></figure>

Now you shoulkd be able to toggle layouts with the *Play* button.&#x20;

## Common Resoulrces (Style file)

Now all of the texts are white. We want to have the default color to be specified in a Style file that can be changed just once and the reused across all layouts.&#x20;

First right-click on the project, select *Add* and then click *Resource Dictionary (WPF)* and name it *Styles.xaml.*&#x20;

Inside the `ResourceDictionary` node, add this line to define a default brush with color Red: \
`<Brush x:Key="DefaultForeground">Red</Brush>`

We need to make ScreensPro aware of this style file, therefore click *Config* - *Settings* in ScreensPro and go to *RenderManager* - *StyleFilenames* and add *Styles.xaml*. In order for this to become effect restart ScreensPro.&#x20;

Now in both the ClockLayout and FreetextLayout file, add these lines directly as the first node inside the UserControl to make the layouts aware of the resource file to use: \
`<UserControl.Resources>`\
`<ResourceDictionary Source="Styles.xaml" />`\
`</UserControl.Resources>`

Now you can select all the resource file content as local resources. Select the clock element, in the *Properties* view expand *Brush*, click on the arrow next to *Foreground* and select *Local Resource* - *DefaultForeground*: <br>

<figure><img src="https://2559612140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrJ4OFsK3ODNU79IRd1WF%2Fuploads%2FRt9xDAJILe5FFNkyIHjy%2Fimage.png?alt=media&#x26;token=c14fc331-9d8a-4fec-b232-9cdf6113afab" alt="" width="563"><figcaption></figcaption></figure>

The clock element's text should now be displayed in red in trhe preview. Repeat this for the FreetextLayout.&#x20;

Instead of using the Properties view, you can also apply the local resource directly in code via the DynamicResource extension: \
`Foreground="{DynamicResource DefaultForeground}"`
