关于在模板中显示图片的问题?
下面是我自定义的一个模板,其中的图片一行]<Image Name="tImage" Margin="0,5,5,0" Width="150" Source="{Binding pic_byte, Converter={StaticResource ImageConverter}}" /> 不知道为什么就是显示不出来,是不是用法不对?当中有自定义一个转换类,imageconverter这个类没问题,因为我把同样的代码拷贝到
============================================================================以下代码图片能显示出来
<slData:DataGridTemplateColumn Header="图片" Width="50">
<slData:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="tImage" Margin="0,5,5,0" Width="50" Tag="{Binding Path=picture }" MouseLeftButtonDown="Image_MouseLeftButtonDown" Source="{Binding pic_byte, Converter={StaticResource ImageConverter}}" />
</DataTemplate>
</slData:DataGridTemplateColumn.CellTemplate>
</slData:DataGridTemplateColumn>
================================================
以下模板图片显示不出来,调用方法
Button bt = new Button();
bt.DataContext = tmpGr.Attributes;
//ControlTemplate tt = getControlTemplate(tmpGr);
//bt.Template = tt;
bt.Template = (ControlTemplate)this.FindName(TipTemplate);
p.Child = (UIElement)bt;
// bt.VerticalOffset=
Point tmpt = MyMap.MapToScreen(mpt);
// Set where the popup will show up on the screen.
p.VerticalOffset = tmpt.Y;
p.HorizontalOffset = tmpt.X;
// Open the popup.
//p.IsOpen = true ;
string id = tmpGr.Attributes["PopUpFlag"].ToString();
tmpGr.MapTip = bt;
=======以下模板图片显示不出来,其它绑定字段能显示出来,图片路径改一下又能显示Source="img/look.png" ,真是郁闷呀
<ControlTemplate x:Name="pipeline" >
<Grid Background="White" Margin="5" Width="200" Height="300" ShowGridLines="False" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Grid.RowDefinitions >
<RowDefinition Height="160" />
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="130" />
</Grid.ColumnDefinitions >
<Image Name="tImage" Margin="0,5,5,0" Width="150" Source="{Binding pic_byte, Converter={StaticResource ImageConverter}}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Text="事件类型" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Text="{Binding Converter={StaticResource MyDictionaryConverter},ConverterParameter=time, Mode=OneWay}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" Text="上传时间" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" Text="{Binding Converter={StaticResource MyDictionaryConverter},ConverterParameter=time, Mode=OneWay}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Text="上传人员" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="3" Grid.Column="1" Text="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=people, Mode=OneWay}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0" Text="所属街道" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="4" Grid.Column="1" Text="{Binding Converter={StaticResource MyDictionaryConverter},ConverterParameter=street, Mode=OneWay}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="5" Grid.Column="0" Text="详细地址" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="5" Grid.Column="1" Text="{Binding Converter={StaticResource MyDictionaryConverter}, ConverterParameter=address, Mode=OneWay}" />
</Grid>
</ControlTemplate>
[解决办法]
模板文件,没有找到转换程序。你的模板文件如果放在资源文件中,需要把转换程序也在资源文件中标识出来。否则资源文件查找不到转换程序。
[解决办法]
Maptip?我自己用开源代码开发了一个Tooltip,是直接往里面放控件UIElement的,难道你使用的Maptip是定制版的?开发自己的代码,将其他人写的代码,看不惯的就重构....我承认我太理想化了....