做了一个图片旋转的效果运行的时候没有浏览器什么都不显示,贴出代码请各位帮忙看下~

binbinazi 2010-08-24 08:25:36
Code==================================ShopShow.xaml============================================================
<UserControl x:Class="Sample.ShopShow"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid>
<Grid.Background>
<ImageBrush ImageSource="/Silverlig;component/Images/win7-9.jpg" Stretch="Fill"></ImageBrush>
</Grid.Background>
<Image x:Name="shower" Width="180" Height="180" Stretch="Fill" Visibility="Collapsed">
<Image.Effect>
<DropShadowEffect Color="White" BlurRadius="10" Opacity="0.8" ShadowDepth="0"/>
</Image.Effect>
</Image>
<Canvas x:Name="moveCanvas"></Canvas>
<StackPanel Orientation="Horizontal" Margin="300 500 0 0">
<Button Width="50" Height="30" Content="Play" Margin="10" x:Name="btnStart" Click="btnStart_Click"></Button>
<Button Width="50" Height="30" Content="Stop" Margin="10" x:Name="btnStop" Click="btnStop_Click"></Button>
</StackPanel>
</Grid>
</UserControl>
==============================ShopShow.xaml.cs========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Media.Imaging;



namespace Sample
{
public partial class ShopShow : UserControl
{
private double centerX = 400;
private double centerY = 300;
private double Widthh = 300;
private double Heightt = 60;
private double degree = 0;
//项集合类
List<ShopItem> objList = new List<ShopItem>();
private double itemWidth = 160;
private double itemHeight = 80;
private double count = 14;
private double currentOpacity = 0;
private DispatcherTimer timer;
public ShopShow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(ShopShow_Loaded);
}
private void ShopShow_Loaded(object sender, RoutedEventArgs e)
{

timer = new DispatcherTimer();
for (var i = 1; i < count; i++)
{
//实例化用户控件
ShopItem item = new ShopItem();
Image images = item.obj;
//加载图片
Uri uri = new Uri(string.Format("/Silverlig;component/Images/album{0}.png", i), UriKind.RelativeOrAbsolute);
BitmapImage bitmap = new BitmapImage(uri);
images.Source = bitmap;
//绑定控件事件
images.MouseEnter += new MouseEventHandler(images_MouseEnter);
images.MouseLeave += new MouseEventHandler(images_MouseLeave);
images.MouseLeftButtonDown += new MouseButtonEventHandler(images_MouseLeftButtonDown);
//添加用户控件到集合里
objList.Add(item);
moveCanvas.Children.Add(item);
}
timer.Tick += new EventHandler(timer_Tick);
TimeSpan sp = new TimeSpan(0, 0, 0, 0, 20);
timer.Interval = sp;
timer.Start();

}
void images_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Image img = sender as Image;
shower.Visibility = Visibility.Visible;
shower.Source = img.Source;

}

void images_MouseLeave(object sender, MouseEventArgs e)
{
timer.Start();
Image img = (Image)sender;
img.Opacity = currentOpacity;
}

void images_MouseEnter(object sender, MouseEventArgs e)
{
timer.Stop();
Image img = (Image)sender;
currentOpacity = img.Opacity;
img.Opacity = 1;
}

private void btnStart_Click(object sender, RoutedEventArgs e)
{
timer.Start();
}

private void btnStop_Click(object sender, RoutedEventArgs e)
{
timer.Stop();
}
private void timer_Tick(object sender, EventArgs e)
{
StartMove();
}
private void StartMove()
{
for (var i = 0; i < objList.Count; i++)
{
//根据控件总数和圆周计算一个平均值
var tmp = (degree + (360 / count) * i) % 360;
tmp = tmp * Math.PI / 180;
var posx = (Widthh) * Math.Sin(tmp);//更新X
var posy = (Heightt) * Math.Cos(tmp);//更新Y
ShopItem obj = objList[i];
//根据宽搞计算缩放比例
double scale = (2 * Heightt - posx) / (3 * Heightt + itemHeight / 2);
Canvas.SetLeft(obj, centerX + posx - (itemWidth / 2) * scale);
Canvas.SetTop(obj, centerY - posy - (itemHeight / 2) * scale);
Canvas.SetZIndex(obj, int.Parse(Math.Ceiling(count * scale).ToString()));
//创建并应用变形属性
ScaleTransform st = new ScaleTransform();
st.ScaleX = scale;
st.ScaleY = scale;
obj.RenderTransform = st;
obj.Opacity = scale;
}
degree = degree - 0.3;
}

}
}
=================================
上面的代码,是我自己看了我买的书上面的一个列子做的,但是不知道为什么不显示效果,恳请给为帮忙解决
...全文
128 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
暖枫无敌 2010-08-25
  • 打赏
  • 举报
回复
还有你少ShopItem.xaml文件,你加上去了嘛,你可以参考书中附带例子,我参照那个做出来了,是可以的,你仔细检查下代码。
binbinazi 2010-08-25
  • 打赏
  • 举报
回复
有这个文件啊~~~~你的图片是放在那个里面的啊??
binbinazi 2010-08-24
  • 打赏
  • 举报
回复
我把加载图片的地址写成("../Images/album{0}.png", i),运行的时候也是什么效果都没有!T_T
binbinazi 2010-08-24
  • 打赏
  • 举报
回复
但是这个背景图片的路径("/Silverlig;component/Images/win7-9.jpg")是我在vs2010里面属性选择进去的啊,开始能够显示背景的啊~~~~~!我的图片在silverlight/Images里面!
binbinazi 2010-08-24
  • 打赏
  • 举报
回复
哦~~~·这个是那个银光志上面的列子,现在自己在学习,c#学的不是很好所以遇到很多问题~
ch5201314zt 2010-08-24
  • 打赏
  • 举报
回复
没有指定IMG的源 路径,指定的是Grid的背景颜色
并且指定的路径还不一定正确
暖枫无敌 2010-08-24
  • 打赏
  • 举报
回复
这个不就是银光志中的例子嘛,你的图片路径是不是有问题啊,"/Silverlig;component/Images/win7-9.jpg",怎么还有分号呢?

8,756

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧