8,757
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="BankQueued.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:BankQueued"
xmlns:common="clr-namespace:BankQueued.Common"
mc:Ignorable="d"
Title="MainWindow" Height="500" Width="800">
<Window.Resources>
<Style x:Key="Buttonlist" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock x:Name="MenuName" Margin="0,5,0,0" TextWrapping="Wrap" Text="{TemplateBinding Content}" VerticalAlignment="Center" d:LayoutOverrides="Width, Height" Grid.Row="1" HorizontalAlignment="Center" Foreground="#FF6382CD" FontSize="26.667" FontWeight="Bold"/>
<TextBlock x:Name="MenuNum" Margin="0,5,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Center" d:LayoutOverrides="Width, Height" Grid.Row="2" HorizontalAlignment="Center" Foreground="#FFA5A5A5" FontSize="20" />
<Border x:Name="MenuBtn" Grid.Row="0" Height="150" Cursor="Hand">
<Border.Background>
<ImageBrush ImageSource="{TemplateBinding common:ControlAttachProperty.BgImg}" Stretch="Uniform"/>
</Border.Background>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="MenuBtn">
<Setter.Value>
<ImageBrush ImageSource="{TemplateBinding common:ControlAttachProperty.BgImg}" Stretch="Uniform"/>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#FFFAC952" TargetName="MenuName"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="260"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Background="#FF6389EA">
</StackPanel>
<StackPanel Width="Auto" Height="Auto" DockPanel.Dock="Left" Grid.Row="0" Grid.Column="1">
<Label Content="请点击选择服务内容" HorizontalContentAlignment="Center" FontSize="48" FontWeight="Bold" Foreground="#FF6389EA" Padding="5" Margin="0,100,0,0" FontFamily="Microsoft YaHei" />
<UniformGrid Margin="0,50,0,0" Width="880" Height="560" Rows="2" Columns="3">
<Button Content="个人现金" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/gerenxianjin.png"></Button>
<Button Content="理财业务" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/licai.png"></Button>
<Button Content="个人外汇" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/gerenwaihui.png"></Button>
<Button Content="非现金" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/feixianjin.png"></Button>
<Button Content="对公业务" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/duigong.png"></Button>
<Button Content="VIP" Style="{DynamicResource Buttonlist}" common:ControlAttachProperty.BgImg="Skin/ico/vip.png"></Button>
</UniformGrid>
</StackPanel>
<TextBlock x:Name="tg" Margin="0,0,0,0" TextWrapping="Wrap" Text="个人现金业务" VerticalAlignment="Center" d:LayoutOverrides="Width, Height" Grid.Row="1" HorizontalAlignment="Center" Foreground="#FFECECEC" FontSize="26.667" FontWeight="Bold"/>
</Grid>
</Window>
public static class ControlAttachProperty
{
/// <summary>
/// 背景图片
/// </summary>
public static readonly DependencyProperty BgImgProperty = DependencyProperty.RegisterAttached(
"BgImg", typeof(string), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(null));
public static string GetBgImg(DependencyObject d)
{
return (string)d.GetValue(BgImgProperty);
}
public static void SetBgImg(DependencyObject obj, string value)
{
obj.SetValue(BgImgProperty, value);
}
}
<Style x:Key="Buttonlist" TargetType="{x:Type Button}">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock x:Name="MenuName" Margin="0,5,0,0" TextWrapping="Wrap" Text="{TemplateBinding Content}" VerticalAlignment="Center" d:LayoutOverrides="Width, Height" Grid.Row="1" HorizontalAlignment="Center" Foreground="#FF6382CD" FontSize="26.667" FontWeight="Bold"/>
<TextBlock x:Name="MenuNum" Margin="0,5,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Center" d:LayoutOverrides="Width, Height" Grid.Row="2" HorizontalAlignment="Center" Foreground="#FFA5A5A5" FontSize="20" />
<Image x:Name="Img" Height="150" Source="{TemplateBinding common:ControlAttachProperty.BgImg}" Stretch="Uniform"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" TargetName="MenuBtn" Value="{TemplateBinding common:ControlAttachProperty.BgImg}"/>
<Setter Property="Foreground" Value="#FFFAC952" TargetName="MenuName"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>