ControlTemplate 은 컨트롤의 모습이나 이벤트 처리등을 미리 정의해 놓고 가져다 쓰는 것을 말합니다.

아래 예시를 보시면 아시겠지만 RadioButton 앞의 라디오 박스가 사라지고

선택시 글자를 굵게 표시하고 주변으로 사각형이 그려집니다.

 

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <StackPanel>

        <StackPanel.Resources>

            <ControlTemplate

                 x:Key="rectRadioButton"

                 TargetType="{x:Type RadioButton}">

                <Border

                    Name="border"

                    BorderBrush="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"

                    CornerRadius="0"

                    Padding="10"

                    BorderThickness="0"

                    Margin="2"

                    Width="250">

                    <ContentPresenter

                        Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center"/>

                </Border>

                <ControlTemplate.Triggers>

                    <Trigger

                         Property="IsChecked"

                         Value="True">

                        <Setter

                             TargetName="border"

                             Property="BorderThickness"

                             Value="3" />

                        <Setter

                             Property="FontWeight"

                             Value="Bold" />

                    </Trigger>

                </ControlTemplate.Triggers>

            </ControlTemplate>

        </StackPanel.Resources>

        <GroupBox

             HorizontalAlignment="Center"

             VerticalAlignment="Center"

             FontSize="12pt"

             Header="Select Option">

            <StackPanel>

                <RadioButton

                    Template="{StaticResource rectRadioButton}"

                    HorizontalAlignment="Center"

                    Content="Template RadioButton 1"

                    IsChecked="True" />

                <RadioButton

                     Template="{StaticResource rectRadioButton}"

                     HorizontalAlignment="Center"

                     Content="Template RadioButton 2" />

                <RadioButton

                     Template="{StaticResource rectRadioButton}"

                     HorizontalAlignment="Center"

                     Content="Template RadioButton 3" />

                <RadioButton

                     Template="{StaticResource rectRadioButton}"

                     HorizontalAlignment="Center"

                     Content="Template RadioButton 4" />

            </StackPanel>

        </GroupBox>

    </StackPanel>

</Window>

 

 

 

Style.Triggers 를 이용하여 Control 에 액션을 취한경우 어떠한 처리를 할 수 있습니다.

아래 예시는 Button, Label 에 마우스를 올렸을때 글자가 파란색으로 굵게 나타도록 한 것입니다.

Button 은 클릭시 글자 색을 변경합니다.

 

<Window x:Class="WpfApp3.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <StackPanel>

        <StackPanel.Resources>

            <Style

                x:Key="normal">

                <Setter

                    Property="Control.FontSize"

                    Value="20" />

                <Setter

                    Property="Control.HorizontalAlignment"

                    Value="Center" />

                <Style.Triggers>

                    <Trigger

                        Property="Control.IsMouseOver"

                        Value="true">

                        <Setter

                            Property="Control.FontWeight"

                            Value="Bold" />

                        <Setter

                            Property="Control.Foreground"

                            Value="Blue" />

                    </Trigger>

                    <Trigger

                        Property="Button.IsPressed"

                        Value="true">

                        <Setter

                            Property="Control.Foreground"

                            Value="Red" />

                    </Trigger>

                </Style.Triggers>

            </Style>

        </StackPanel.Resources>

        <Button Style="{StaticResource normal}" Content="Test Button"/>

        <Label Style="{StaticResource normal}" Content="Test Label"/>

    </StackPanel>

</Window>

 

 

 

* MouseOver

  >     >

 

* Button Click

 

WebView 에 특정 url 을 보여주려고 했는데 아래 처럼 에러가 발생되었습니다.

 

net::ERR_CLEARTEXT_NOT_PERMITTED

 

 

확인해 보니 Android OS 9 Pie 버전부터는 WebView에 "http://" URL 접근이 안된다고 합니다.

 

해당 오류를 해결하기위해선 안드로이드 프로젝트의 AndroidManifest.xml 파일의 내용에

아래 굵게 표시된 내용을 추가하면 됩니다. (android:usesCleartextTraffic="true")

 

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.test" android:installLocation="auto">

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />

<application

           android:label="test.Android"

           android:usesCleartextTraffic="true">

       </application>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.INTERNET" />

</manifest>

 

위처리를 하고 다시 앱을 실행하니 아래처럼 url 내용이 잘 나타났습니다.