This commit is contained in:
Javier Suárez Ruiz 2019-11-17 19:07:24 +01:00
Родитель eee9dd0acc
Коммит c8c2991e3a
3 изменённых файлов: 64 добавлений и 0 удалений

64
README.md Normal file
Просмотреть файл

@ -0,0 +1,64 @@
# Xamarin.Forms Composite Controls
In this repository there are only some tests related to the idea of composite controls and above all have a **Template** property and be able to use **ControlTemplate** to customize a control.
## Let's see more details!
For these tests we have created a Slider Composite control (composed of other Views that make up the control).
![Composite Control](images/composite-control.png)
We have the same visual appearance, properties and events. However, the control has a Template property that allows us to modify the ControlTemplate that defines the control.
We modify the Slider ControlTemplate:
```
<ControlTemplate x:Key="CustomSliderTemplate">
<Grid
VerticalOptions="Center"
Margin="10, 0">
<BoxView
x:Name="MaximumTrack"
BackgroundColor="Green"
Margin="6,0"
CornerRadius="6"
HeightRequest="6"
Opacity="0.24"
VerticalOptions="Center" />
<BoxView
x:Name="MinimumTrack"
BackgroundColor="Green"
Margin="6,0"
CornerRadius="6"
HeightRequest="6"
HorizontalOptions="Start"
InputTransparent="True"
VerticalOptions="Center"
WidthRequest="0" />
<Image
x:Name="Thumb"
Margin="0"
BackgroundColor="Transparent"
Source="football.png"
HeightRequest="36"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="36" />
</Grid>
</ControlTemplate>
```
And we use it:
```
<Slider
ControlTemplate="{StaticResource CustomSliderTemplate}"/>
```
The result:
![ControlTemplate](images/slider-controltemplate.png)
We can use XAML Hot Reload to adjust the appearance:
![Using XAML Hot Reload](images/xamarinforms-edit-controltemplate.gif)

Двоичные данные
images/composite-control.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.8 KiB

Двоичные данные
images/slider-controltemplate.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.0 KiB