■やろうとしていること
オリジナルのボタンのデザインをリソースディクショナリに定義しようとしています。
そのボタンは四角い枠線があり、その中に画像ファイルとテキストを包含しています。
枠線の色とテキストを、MouseOverとクリック時に色を変えたいです。
現在作ったXAMLは以下です。sampleという名前でスタイルを定義し、ボタンに適用ています。
XAML
1<Window x:Class="ResourceDic.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:ResourceDic" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="450" Width="800"> 9 <Window.Resources> 10 <Style TargetType="Button" x:Key="sample"> 11 <Setter Property="Template"> 12 <Setter.Value> 13 <ControlTemplate TargetType="Button"> 14 <Border Name="border" BorderThickness="4" BorderBrush="Green"> 15 <StackPanel Orientation="Horizontal" Background="Transparent"> 16 <Image Name="image" Source="Resources/aaa.png" /> 17 <TextBlock Name="text" FontSize="72" VerticalAlignment="Center">あいうえお</TextBlock> 18 </StackPanel> 19 </Border> 20 <ControlTemplate.Triggers> 21 <Trigger Property="IsMouseOver" Value="true"> 22 <Setter TargetName="border" Property="BorderBrush" Value="blue" /> 23 <Setter TargetName="text" Property="Foreground" Value="blue" /> 24 </Trigger> 25 <Trigger Property="IsPressed" Value="true"> 26 <Setter TargetName="border" Property="BorderBrush" Value="red" /> 27 <Setter TargetName="text" Property="Foreground" Value="red" /> 28 </Trigger> 29 </ControlTemplate.Triggers> 30 </ControlTemplate> 31 </Setter.Value> 32 </Setter> 33 </Style> 34 </Window.Resources> 35 36 <Grid> 37 <Viewbox Height="100" Width="100" HorizontalAlignment="Center"> 38 <Button Style="{StaticResource sample}" /> 39 </Viewbox> 40 </Grid> 41 42</Window>
■困っていること
上記コードでは画像が「aaa.png」、テキストが「あいうえお」に固定になってしまいます。
リソースディクショナリの呼び出し側から、画像ファイルとテキストは指定できるようにしたいです。
どのようにすればできますでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/27 12:39