前端页面:
<UserControl x:Class="QuJiao.BannerViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:QuJiao"
xmlns:quJiao="clr-namespace:QuJiao;assembly=QuJiaoManager"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<!-- board样式 -->
<Style x:Key="boardStyle" TargetType="Canvas">
<Setter Property="Width" Value="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:BannerViewer}}"/>
<Setter Property="Height" Value="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:BannerViewer}}"/>
<Setter Property="ClipToBounds" Value="True"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
<!-- banner图片 -->
<Style x:Key="bannerImgStyle" TargetType="Image">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Width" Value="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:BannerViewer}}"/>
<Setter Property="Height" Value="{Binding Path=ActualHeight,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:BannerViewer}}"/>
<Setter Property="Stretch" Value="Fill"/>
</Style>
<!-- banner列表 -->
<Style x:Key="bannerImgListStyle" TargetType="{x:Type ItemsControl}">
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/>
<!-- 可以隐藏不可禁用,否则不能滚动了 -->
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<ScrollViewer x:Name="imgScroll"
Tag="imgScroll"
Style="{StaticResource ScrollViewerThin}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<!-- 点击广告 -->
<Grid Tag="{Binding redirect_url}" MouseUp="ItemImg_OnMouseUp">
<Image x:Name="itemImg" Style="{StaticResource bannerImgStyle}" Source="{Binding image_url,Converter={StaticResource ConvertNameToBitmapImage}}"/>
</Grid>
<DataTemplate.Triggers>
<!-- 有链接时鼠标变为手型 -->
<DataTrigger Binding="{Binding redirect_url,Converter={StaticResource BoolConvertStringIfNullOrEmpty}}" Value="False">
<Setter Property="Cursor" Value="Hand"/>
</Da