我想在WPF应用程序中动态创建图像控件,并设置该控件的属性...像大小,位置,颜色,sizemode 我该怎么做?给我任何样本码。动态生成WPF应用程序中的图像控制
-1
A
回答
1
这是一个简单的例子,我已经做了哪些加载在标志堆栈溢出。
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var webImage = new BitmapImage(new Uri("http://sstatic.net/so/img/logo.png"));
var imageControl = new Image();
imageControl.Source = webImage;
ContentRoot.Children.Add(imageControl);
}
}
和XAML ...
<Window x:Class="WpfExamples.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="ContentRoot">
</Grid>
</Window>
干杯,
安德鲁
0
你想显示一个图像文件或流?或者你要创建一个图像控件,并将其添加到代码中的窗口?
+0
我想创建作为Image控件动态地设置属性s的控制 – Suryakavitha 2010-02-06 08:47:23
0
从here,MSDN上
// Create Image Element
Image myImage = new Image();
myImage.Width = 200;
// Create source
BitmapImage myBitmapImage = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg");
// To save significant application memory, set the DecodePixelWidth or
// DecodePixelHeight of the BitmapImage value of the image source to the desired
// height or width of the rendered image. If you don't do this, the application will
// cache the image as though it were rendered as its normal size rather then just
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
//set image source
myImage.Source = myBitmapImage;
+0
好的...但我必须创建10个图像控件,然后我必须将它们放在单个应用程序中....现在,我可以做什么 – Suryakavitha 2010-02-06 09:53:57
相关问题
- 1. 当Web应用程序动态生成Excel和图像文件
- 2. wpf应用程序中的图像控制无法正常显示图像
- 3. 使用wpf的图像滑动控制
- 4. 。c控制台应用程序自动完成动态参数
- 5. 生成控制器空的应用程序视图文件夹
- 6. Tapestry动态生成图像
- 7. 动态生成iPhone/iPad应用程序的开始图像的好方法
- 8. 定制UIAlertController - 应用程序试图把模态启动控制
- 9. 用Django为动态生成的图像
- 10. PHP中的动态图像生成
- 11. WPF应用程序的VNC控制
- 12. 在wpf应用程序中动态更改用户控件
- 13. 从HTTP处理程序中的WPF用户控件创建动态图像
- 14. Rails应用程序生成错误:父控制器中的ID
- 15. ContentPage的动态控制ID生成
- 16. 在asp.net中动态生成图像?
- 17. WPF /控制台混合应用程序
- 18. 生成动态流程图
- 19. 从另一个应用程序控制WPF应用程序
- 20. 在控制台应用程序中生成html文件
- 21. 在WPF中生成缩略图图像
- 22. WPF DataGrid中的动态列生成
- 23. ASP.NET MVC动态生成的图像URL
- 24. 清除动态生成的图像
- 25. 缓存动态生成的图像
- 26. Django和动态生成的图像
- 27. 控制台应用程序中的显示图像
- 28. Android动态控制生成器
- 29. 从S3的Rails应用程序控制器生成静态网站?
- 30. WindowsForm应用程序生成在Visual Studio控制台应用程序
好吧...但我必须创建10个图像控件,然后我必须将它们放在单个应用程序....现在我能做什么: – Suryakavitha 2010-02-06 09:05:00
请不要再问同样的问题。如果您想添加更多详细信息,可以使用这些注释上方的“编辑”链接编辑您的问题。 – 2010-02-06 12:49:16