WPF XMAL Static Resources kullanımı

WPF XMAL Static Resources kullanımı

Önceki yazılarımızda hesap makinesi yapmıştık ve bir önceki yazımızda butonları renklendirmiştir. Şimdi StaticResources tanımlayarak bu butonları aynı anda renklendirmeyi görelim.

<Window x:Class="WPFGiris.D3.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:WPFGiris.D3"         mc:Ignorable="d"         Title="Hesap Makinesi" Height="525" Width="350">      <Window.Resources>         <SolidColorBrush x:Key="numbersColor" Color="#000000"/>         <SolidColorBrush x:Key="operatorsColor" Color="Green" />     </Window.Resources>               <Grid Margin="10">                  <Grid.ColumnDefinitions>             <ColumnDefinition Width="*"/>             <ColumnDefinition Width="*"/>             <ColumnDefinition Width="*"/>             <ColumnDefinition Width="*"/>         </Grid.ColumnDefinitions>         <Grid.RowDefinitions>             <RowDefinition Height="2*"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/>         </Grid.RowDefinitions>         <Label x:Name="resultLabel" Content="0" Grid.ColumnSpan="4" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="60"/>         <Button x:Name="acButton" Click="AcButton_Click" Content="AC" Grid.Row="1" Margin="5"/>         <Button x:Name="negativeButton" Click="NegativeButton_Click" Content="+/1" Grid.Row="1" Grid.Column="1" Margin="5"/>         <Button x:Name="percentageButton" Click="PercentageButton_Click" Content="%" Grid.Row="1" Grid.Column="2" Margin="5"/>         <Button x:Name="divisionButton" Click="OperationButton_Click" Content="/" Grid.Row="1" Grid.Column="3" Margin="5"                 Background="{StaticResource operatorsColor}" Foreground="White"/>         <Button x:Name="sevenButton" Click="NumberButton_Click" Background="{StaticResource numbersColor}" Foreground="#FFFFFF" Content="7" Grid.Row="2" Grid.Column="0" Margin="5"/>         <Button x:Name="eightButton" Click="NumberButton_Click" Content="8" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="2" Grid.Column="1" Margin="5"/>         <Button x:Name="nineButton" Click="NumberButton_Click" Content="9" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="2" Grid.Column="2" Margin="5"/>         <Button x:Name="multiplicationButton" Click="OperationButton_Click"  Background="{StaticResource operatorsColor}" Foreground="White" Content="*" Grid.Row="2" Grid.Column="3" Margin="5"/>         <Button x:Name="fourButton" Click="NumberButton_Click" Content="4" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="3" Grid.Column="0" Margin="5"/>         <Button x:Name="fiveButton" Click="NumberButton_Click" Content="5" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="3" Grid.Column="1" Margin="5"/>         <Button x:Name="sixButton" Click="NumberButton_Click" Content="6" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="3" Grid.Column="2" Margin="5"/>         <Button x:Name="substractionButton" Click="OperationButton_Click" Background="{StaticResource operatorsColor}" Foreground="White" Content="-" Grid.Row="3" Grid.Column="3" Margin="5"/>         <Button x:Name="oneButton" Click="NumberButton_Click" Content="1" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"   Grid.Row="4" Grid.Column="0" Margin="5"/>         <Button x:Name="twoButton" Click="NumberButton_Click"  Content="2" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="4" Grid.Column="1" Margin="5"/>         <Button x:Name="threeButton" Click="NumberButton_Click"  Content="3" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Row="4" Grid.Column="2" Margin="5"/>         <Button x:Name="plusButton" Click="OperationButton_Click" Background="{StaticResource operatorsColor}" Foreground="White" Content="+" Grid.Row="4" Grid.Column="3" Margin="5"/>         <Button x:Name="zeroButton" Click="NumberButton_Click" Content="0" Grid.Row="5" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.ColumnSpan="2" Margin="5"/>         <Button x:Name="dotButton" Click="DotButton_Click"  Content="." Grid.Row="5" Background="{StaticResource numbersColor}" Foreground="#FFFFFF"  Grid.Column="2" Margin="5"/>         <Button x:Name="equalButton" Click="EqualButton_Click" Background="{StaticResource operatorsColor}" Foreground="White" Content="=" Grid.Row="5" Grid.Column="3" Margin="5" Cursor="Hand"/>     </Grid> </Window> 

Görselde de yer aldığı üzere XMAL ekranında Window üst bilgisi bittiğinde <Window.Resources> etiketiyle StaticResource tanımlayamaya başlıyoruz. Ardından paylaştığım kodu ekrandaki gibi yazıp butonun Background kısmında da oluşturduğunuz StaticResource yi işaret ediyorsunuz.


Yayımlandı

kategorisi

yazarı:

Etiketler:

Yorumlar

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir