我想在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. 如何创建动态图像控制城域应用程序
- 3. wpf应用程序中的图像控制无法正常显示图像
- 4. 使用wpf的图像滑动控制
- 5. C#控制台应用程序将图形生成为位图
- 6. 生成控制器空的应用程序视图文件夹
- 7. 计算在Windows窗体应用程序动态生成的控制
- 8. 定制UIAlertController - 应用程序试图把模态启动控制
- 9. 动态生成iPhone/iPad应用程序的开始图像的好方法
- 10. 动态生成图像?
- 11. Tapestry动态生成图像
- 12. .NET动态图像生成
- 13. PHP - 动态图像生成
- 14. WPF应用程序的VNC控制
- 15. 在wpf应用程序中动态更改用户控件
- 16. 从HTTP处理程序中的WPF用户控件创建动态图像
- 17. 用Django为动态生成的图像
- 18. PHP中的动态图像生成
- 19. 找不到动态生成的控件,使用WPF中的FindName()
- 20. 在WPF应用程序中控制事件驱动的导航
- 21. Rails应用程序生成错误:父控制器中的ID
- 22. vb.net中的动态图像控制
- 23. WPF /控制台混合应用程序
- 24. ContentPage的动态控制ID生成
- 25. C#WPF:从动态生成的图像文件加载数据
- 26. 使用.htaccess动态图像生成
- 27. 用css和javascript动态生成图像
- 28. 在asp.net中动态生成图像?
- 29. 生成动态流程图
- 30. 从另一个应用程序控制WPF应用程序
好吧...但我必须创建10个图像控件,然后我必须将它们放在单个应用程序....现在我能做什么: – Suryakavitha 2010-02-06 09:05:00
请不要再问同样的问题。如果您想添加更多详细信息,可以使用这些注释上方的“编辑”链接编辑您的问题。 – 2010-02-06 12:49:16