8,756
社区成员




<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:WpfApplication6"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<converters:BoolToSource x:Key="booltosource"></converters:BoolToSource>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<Image x:Name="img" Grid.Row="0" Grid.ColumnSpan="2" Source="{Binding Path=URL, Converter={StaticResource booltosource}}"/>
<TextBox x:Name="tb" Grid.Column="0" Grid.Row="1"></TextBox>
<Button x:Name="bt" Content="点击" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" Height="50" Click="bt_Click"></Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows.Data;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
namespace WpfApplication6
{
[ValueConversion(typeof(bool), typeof(BitmapImage))]
class BoolToSource:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool temp =(bool) value;
if (temp)
return new BitmapImage(new Uri("Images\\red.ico", UriKind.Relative));
else
return new BitmapImage(new Uri("Images\\green.ico", UriKind.Relative));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication6
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
Binding bd = new Binding();
bool ss;
public MainWindow()
{
InitializeComponent();
ss=true ;
bd.Source = ss;
bd.Path = new PropertyPath("URL");
this.img.SetBinding(Image.SourceProperty, bd);
}
private void bt_Click(object sender, RoutedEventArgs e)
{
}
}
}
return new BitmapImage(new Uri(string.Format(@"\Image\{0}.png",eIcon), UriKind.RelativeOrAbsolute));
自己在Converter类里打个断点,走走看。
return new BitmapImage(new Uri(string.Format(@"\Image\{0}.png",eIcon), UriKind.RelativeOrAbsolute));
自己在Converter类里打个断点,走走看。[/quote]
谢谢你的帮助,我已经搞定了,分数已奖励。