Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WPF勉強会 第4回 スタイルの初歩/WPFStudy4

WPF勉強会 第4回 スタイルの初歩/WPFStudy4

WPF勉強会 第4回 スタイルの初歩

説明後に実演するライブコーディングのコードはこちら。
https://github.com/hachiilcane/WpfStudy

Avatar for hachiilcane

hachiilcane

March 01, 2022
Tweet

More Decks by hachiilcane

Other Decks in Programming

Transcript

  1. CSSͱࣅ͍ͯΔͱ͜Ζ ఆٛ͢Δ৔ॴͰద༻ൣғ͕มΘΔ ผϑΝΠϧʢϦιʔεσΟΫγϣφϦʣ> Application಺ > Window಺ > Page಺ > ύωϧ಺ʢGridͱ͔ʣ

    > 1ͭͷ ίϯτϩʔϧ಺ > Template಺ ఆ͕͔ٛͿͬͨ৔߹͸࠷ޙʹએݴͨ͠΄͏͕উͭ ݟͨ໨ͱϩδοΫΛ෼཭Ͱ͖Δ XAML͚ͩͰݟͨ໨Λࣗ༝ʹม͑ΒΕΔ
  2. ؆୯ͳྫ ඞͣTargetType͕ඞཁ C#͔ͩΒܕ͸ݫີͳͷͰ͢ <Page.Resources> <Style TargetType="Button"> <Setter Property="Background" Value="AliceBlue"/> <Setter

    Property="FontSize" Value="14"/> </Style> </Page.Resources> <Grid> <UniformGrid> <Button Content="Button1"/> <Button Content="Button2"/> <Button Content="Button3"/> </UniformGrid> </Grid>
  3. x:Keyଐੑॏཁʂ x:Keyଐੑ͕ແ͍ͱɺTargetTypeͰࢦఆͨ͠ܕશ෦ʹద༻ x:Keyଐੑ͕͋ΔͱɺͦͷΩʔΛࢦఆͨ͠΋ͷ͚͕ͩద ༻ <Page.Resources> <Style x:Key="BlueButtonStyle" TargetType="Button"> <Setter Property="Background"

    Value="AliceBlue"/> <Setter Property="FontSize" Value="14"/> </Style> </Page.Resources> <Grid> <UniformGrid> <Button Content="Button1"/> <Button Content="Button2" Style="{StaticResource BlueButtonStyle}"/> <Button Content="Button3"/> </UniformGrid> </Grid>
  4. BasedOnͰܧঝͰ͖·͢ ผͷελΠϧΛج ʹɺελΠϧͷ௥Ճ ͕Ͱ͖Δ <Page.Resources> <Style TargetType="Button"> <Setter Property="Background" Value="AliceBlue"/>

    <Setter Property="FontSize" Value="14"/> </Style> <Style x:Key="AmazingButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="RenderTransform"> <Setter.Value> <RotateTransform Angle="10"/> </Setter.Value> </Setter> </Style> </Page.Resources> <Grid> <UniformGrid> <Button Content="Button1"/> <Button Content="Button2" Style="{StaticResource AmazingButtonStyle}"/> <Button Content="Button3"/> </UniformGrid> </Grid>
  5. ϒϥγ͸Ϧιʔεʹ͠ͱ ͘ͱศར ࢖͍ճ͕͠Ͱ͖ΔͷͰɺޙͰશମͷ৭ຯΛม ͑΍͍͢ Πϯελϯε͕1ݸͰࡁΉ <Page.Resources> <SolidColorBrush x:Key="ButtonBackColor" Color="AliceBlue"/> <Style

    TargetType="{x:Type Button}"> <Setter Property="Background" Value="{StaticResource ButtonBackColor}"/> <Setter Property="FontSize" Value="14"/> </Style> </Page.Resources>