--图片页面:
<Window x:Class="DataGridDemo.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:cv="clr-namespace:DataGridDemo.Converter"
Title="Window3" Height="300" Width="300">
<Window.Resources>
<cv:PropertyValuesToImageConverter x:Key="CvPropertyValuesToImage" />
<Style TargetType="CheckBox" x:Key="OkSty">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Image>
<Image.Source>
<MultiBinding Converter="{StaticResource CvPropertyValuesToImage}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type CheckBox}}" Path="IsMouseOver" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type CheckBox}}" Path="IsChecked" />
<!--<Binding>
<Binding.Source>
<sys:Boolean>false</sys:Boolean>
</Binding.Source>
</Binding>-->
</MultiBinding>
</Image.Source>
</Image>
<!--<ContentPresenter Visibility="Collapsed"/>-->
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<CheckBox Content="OK" Style="{StaticResource OkSty}" IsChecked="False">
</CheckBox>
</Grid>
</Window>
-- Converter注:其中图片建一个资源项目,然后右键设为resouse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.Globalization;
namespace DataGridDemo.Converter
{
class PropertyValuesToImageConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
BitmapImage image = null;
try
{
Boolean isMouserOver = (bool)values[0];
Boolean isChecked = (bool)values[1];
String path = "pack://application:,,,/DataGridDemo.Resouse;component/Images/";
if (!isMouserOver && isChecked)
path = path + "Checkbox_Selected.png";
if (isMouserOver && isChecked)
path = path + "Checkbox_Selected_Click.png";
if (!isMouserOver && !isChecked)
path = path + "Checkbox_UnSelected.png";
if (isMouserOver && !isChecked)
path = path + "Checkbox_UnSelected_Click.png";
if (!String.IsNullOrEmpty(path))
image = new BitmapImage(new Uri(path, UriKind.Absolute));
return image;
}
catch (Exception)
{
return null;
}
}
object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}