|
Try using this method instead:
public static BitmapImage BitmapImageFromBytes(byte[] bytes)
{
BitmapImage image = null;
MemoryStream stream = null;
try {
stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
image = new BitmapImage();
image.BeginInit();
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.StreamSource.Seek(0, SeekOrigin.Begin);
image.EndInit();
}
catch (Exception ex)
{
if (ex != null)
{
}
throw;
}
finally {
stream.Close();
stream.Dispose();
}
return image;
} This requires you to import System.Drawing , but it does the job.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Worked like a champ. Many thanks.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
No probs mate.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
John Simmons / outlaw programmer wrote: image.DecodePixelWidth = desiredX;
image.DecodePixelHeight = desiredY;
image.EndInit();
I found out tonight that this is a waste of time. I spent ages trying to load an image to be the same size it was on disc, and while the PixelWidth and PixelHeight would be correct, nothing I did could get the actual Width and Height to be right. To be clear, I found it was next to impossible to take an 800x600 jpg on my hard drive, and load it in WPF to be 800 x 600 in size.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I think you mentioned it in another post, but it's due to the DPI and the way wpf displays images...
link[^]
|
|
|
|
|
Yeah,the whole DPI thing is an absolute nightmare. I tried to do something like what you linked to, but it was too complex in the context of our program, I couldn't get the image control to size how I wanted it to.
My main point was, I requested an image of a specific size and got something else back - the framework is just a nightmare in this regard.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi all,
I am in the following situation: I am writing my own "application framework" *WOW* - just for myself, nothing generally interesting There I want to implement a base class for applications - lets call it AppBase which is derived from System.Windows.Application. A concrete WPF application is to use AppBase as base class for the partial class MyApp.App in the file App.XAML.cs.
Now when compiling a concrete WPF application a code generator transforms the XAML code of MyApp.App into c# and puts System.Windows.Application as base class for the generated part in App.g.cs.
This leads to the situation that the compiler complains that I am not to use different base classes for my partial class MyApp.App.
What I am wondering is: Is there a way to tell the code generator which base class to use?? Any other way to enable the specification of custom base classes for WPF applications is also wellcome.
Thanks in advance.
Lars
#pragma error( disable : * )
|
|
|
|
|
Hi,
I am working on a RSS feeds application using Silver light 2.0. In this I am using WPF service for solving the cross domain problem. But for this web service I have to use System.ServiceModel.Syndication namespace. For adding this to my application to my application I looked in Add reference --> .Net tabs but I cannot find it there.
Please reply me how can I add this to my application.
Thanks in Advance
|
|
|
|
|
You can't. Silverlight uses a separate set of Silverlight assemblies because these are the ones that are available at the client end as part of the Silverlight download. This means that you get a subset of WPF/.NET functionality.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
If you upgrade your application to Silverlight 3, the Syndication classes are there.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
I have 3 controls using in a wpf window..textbox, listbox and listview.
The textbox is like a searching textbox, where i search for Folder's in a particular folder, the list of searched folders will be displayed in listbox. I am able to do until this part.
Now, if I select any of the displayed folders in the listbox, then the files available in the particular folder should be displayed in the ListView. (missing out the link b/w the 2 here).
eg : I have 3 folders displayed in listbox (say folder1, folder2, folder3).each folder has few excel files. I selected folder 2 ( which has 5 excel files, mark.xls, steve.xls, cary.xls, rick.xls and jenny.xls and also a subfolder inside that called Launch1).
Now, the List view should show the folder2 contents divided into 3 columns, ( col1, col2, col3).
Name Desc Date
-------------------------------------------------------------------------------------------------------------
Mark this is mark's excel 07/20/2009
steve this is steve's excel. 07/22/2009
cary ............ ..................
rick .................... ........................
jenny .................... ...........................
------------------------------------------------------------------------------------
+ Launch1
Again Launch1 folder might have few workbooks, so I have put a plus on it.. so when + is clicked.. it shuold display the files inside this folder.
I am using Xaml and C#... please help.
Thank You,
Ramm
|
|
|
|
|
Which bit are you stuck on ? What have you already written ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I am following Sergey Zwezdin's blog "Windows 7 programming: Taskbar. Part 5 – CustomWindowsManager[^]" for creating the CustomWindowManager object.
As much as I gone thru the code, I realised that, I can create a custom preview window for the Windows 7 taskbar for the Window using it's handle. I want to do the same thing for the UserControl. How can I achieve this, as this only takes parameter of Windows & Windows handle.
My problem is: on click of a button I will create an object of an UserControl & then I will display it on the screen as a MwiChildWindow (Just like MDI form). I am able to create the MwiWindow & it's children but unable to show the child in the Taskbar previews. If I have four child windows (UserControls) visible in the main Window... I am getting only one preview of the Window.
I want to create 5 previews (1 MainWindow & 4 opened Child Window) to be visible in the pane.
Can anyone please guide me to resolve the same as early as possible? I didn't find anything on the net.
I am using Visual Studio 2008 SP1 (WPF 3.5 SP1) with Windows7APICodePack.
Looking forward... Thanks in advance.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
After doing lots of analysis I got the solution. I am sharing the same for the benefit of others:
First we have to register the two events:
Taskbar.TabbedThumbnail.TabbedThumbnailActivated += new EventHandler<TabbedThumbnailEventArgs>(TabbedThumbnail_TabbedThumbnailActivated);
Taskbar.TabbedThumbnail.TabbedThumbnailClosed += new EventHandler<TabbedThumbnailEventArgs>(TabbedThumbnail_TabbedThumbnailClosed);
Then do the implementation of the registered events:
void TabbedThumbnail_TabbedThumbnailClosed(object sender, TabbedThumbnailEventArgs e)
{
}
void TabbedThumbnail_TabbedThumbnailActivated(object sender, TabbedThumbnailEventArgs e)
{
}
Now ehen you want to add the usercontrol... do the following steps:
TabbedThumbnailPreview thumnailPreview = new TabbedThumbnailPreview(this, myUserControl);
thumnailPreview.Title = "My UserControl Title";
thumnailPreview.InvalidatePreview();
Taskbar.TabbedThumbnail.AddThumbnailPreview(thumnailPreview);
That's it...
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
Whenever an item is selected in the listview I am wanting to basically just get the value of the first selected item in the first column.
It seems it is not done the same way in C# as with C# WPF. Could you provide me with somewhere I can learn how to do this?
|
|
|
|
|
I created an Expression MediaPlayer app with Encoder 2 using the SL2Gallery template. The app works perfectly stand-alone but I want to put the player on a page in another Silverlight 2 app. The playlist for the original app is supplied to the .xap through initParams. I copied the entire Page.xaml into my page (changed the namspace etc) and added the playlist to the player as follows. It almost works. I have three problems.
1. The playlist listbox acts as though the scroll area is only two items long. It's plenty big to show all of the items. Sometimes when scrolling a third item will show up, but it's intermittent.
2. The Thumbs don't display. I've tried every conceivable Build Action, but nothing seems to work. And yes I can see them added to the compilation during the build.
3. If the first two can be solved, I'd like it to auto start when the page opens.
<ExpressionPlayer:ExpressionPlayer Margin="0,0,0,0"
x:Name="myPlayer"
Style="{StaticResource GalleryTemplate}">
<ExpressionPlayer:ExpressionPlayer.Playlist>
<ExpressionMediaPlayer:PlaylistItem Title="Preparing Your Home"
MediaUrl="Properties/video1.wmv"
Description="My Description"
ThumbSource= "Properties/video1_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="2"
MediaUrl="Properties/video2.wmv"
ThumbSource="Properties/video2_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="3"
MediaUrl="Properties/video3.wmv"
ThumbSource="Properties/video3_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="4"
MediaUrl="Properties/video4.wmv"
ThumbSource="Properties/video4_Thumb.jpg"
FrameRate="25" />
</ExpressionPlayer:ExpressionPlayer.Playlist>
</ExpressionPlayer:ExpressionPlayer>
There is very little information on how to use the SL2Gallery template, so if someone could assist I'd appreciate it.
Thanks,
Steve
|
|
|
|
|
Hi Steve,
If you can send the sample project that you are having problems then I will try to see what I can help you.. The code that you pasted here seems fine to me.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Michael,
I created a small app that just included the MediaPlayer in Blend 2 and it worked fine. As soon as I opened it in VS it transformed the project into a SL3 project and it stopped working. I guess I wasn't paying attention the first time. In an attempt to get everything into SL3 I downloaded Encoder 3 (I already have Blend 3), however now apparently Playlist doesn't contain PlaylistItems. At this point I'm totally confused. Plus, our neighbors are having a tree taken down and the noise is driving me crazy!!! I'm going to hang it up for the day and start fresh tomorrow.
Thanks for your offer of help and if I find anything tomorrow I'll post it,
Steve
|
|
|
|
|
Sorry to hear about those behavior in Silverlight 3 and Encoder. Feel free to let me know if you are having the same problem even you start fresh
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Sorry I didn't get back on this; I got busy with other things. I worked it out by modifying the template code. Now it works beautifully!
Thanks for the help,
Steve
|
|
|
|
|
Give me some help please!
|
|
|
|
|
hi error,
There are plenty much commercial solutions out there. Try Google with 'WPF Reporting'.
If you want to keep things simpler and are not afraid of writing a little bit code, you could do the job with WPF's FlowDocument.
Just bind the corresponding fields to TextBlock / TextBox items in the Document and voila ...
First step : Create a FlowDocument with it's content and placeholders.
( This is maybe a very poor example, but it should give you a kick into the right direction )
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
ColumnWidth="400" FontSize="14" FontFamily="Georgia">
<Paragraph>
<!-- Header-->
<TextBlock Text="Header of the Report ...." />
<!-- Binding of Fields -->
<TextBlock Text="{Binding Path=DesiredFieldName}" />
<!-- Footer -->
<TextBlock Text="Footer of the Report ...." />
</Paragraph>
</FlowDocument>
Step two : Instanciate your FlowDocument ( in this case from within C# code )
string xaml = null;
StreamResourceInfo sri = Application.GetResourceStream(new Uri(@"..\Documents\Report.xaml", UriKind.Relative));
using (StreamReader reader = new StreamReader(sri.Stream))
{
xaml = reader.ReadToEnd();
}
FlowDocument myReport = (FlowDocument)XamlReader.Parse(xaml);
Step three : Bind the source to your FlowDocument ( Report ), so it's 'fields get filled' by binding.
For example with the EntityFramework as dataprovider. ( Again this is just an example ! You could do this with nearly every datasource )
using(Entities ctx = new Entities())
{
myReport.DataContext = from c in ctx.articles select c.price;
}
And finally : If you want to show your generated report, you could do so showing it in an FlowDocumentReader.
<FlowDocumentReader Name="myReportViewer" />
And now set our generated report to the Document property of the FlowDocumentReader ...
myReportViewer.Document = myReport;
Let me know if that helped you.
Cheers Doc.NET.Noodles
(PS.: Dont forget to vote if that answer helped you. )
|
|
|
|
|
Just use SQL Reporting Services - there's no need to use a pure WPF solution here.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
This is very basic BackgroundWorker Example but I dont know why the progress bar run 2 times. It should run only 1 time. anyone can help me.
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Threading
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Namespace WindowsApplication1
Partial Public Class Window1
Inherits System.Windows.Window
Private WithEvents _worker As BackgroundWorker
Public Sub New()
InitializeComponent()
End Sub
Private Sub StartWorker(ByVal sender As Object, ByVal e As RoutedEventArgs)
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
_worker = New BackgroundWorker()
_worker.WorkerReportsProgress = True
_worker.WorkerSupportsCancellation = True
AddHandler _worker.DoWork, AddressOf DoWorkEventHandler
AddHandler _worker.ProgressChanged, AddressOf ProgressChangedEventHandler
AddHandler _worker.RunWorkerCompleted, AddressOf RunWorkerCompletedEventHandler
_worker.RunWorkerAsync()
_btnStart.IsEnabled = False
_btnCancel.IsEnabled = True
End Sub
Private Sub DoWorkEventHandler(ByVal s As Object, ByVal args As DoWorkEventArgs) Handles _worker.DoWork
Dim worker As BackgroundWorker = TryCast(s, BackgroundWorker)
For i As Integer = 0 To 4
If worker.CancellationPending Then
args.Cancel = True
Return
End If
Thread.Sleep(100)
worker.ReportProgress(i + 1)
Next i
End Sub
Private Sub ProgressChangedEventHandler(ByVal s As Object, ByVal args As ProgressChangedEventArgs) Handles _worker.ProgressChanged
_progressBar.Value = args.ProgressPercentage
End Sub
Private Sub RunWorkerCompletedEventHandler(ByVal s As Object, ByVal args As RunWorkerCompletedEventArgs) Handles _worker.RunWorkerCompleted
_btnStart.IsEnabled = True
_btnCancel.IsEnabled = False
_progressBar.Value = 0
End Sub
Private Sub CancelWorker(ByVal sender As Object, ByVal e As RoutedEventArgs)
_worker.CancelAsync()
End Sub
End Class
End Namespace
|
|
|
|
|
Member 3068741 wrote: I dont know why the progress bar run 2 times. It should run only 1 time.
I don't see anything that runs twice in there.
Use your debugger - use breakpoint(s). Is button1_Click called more than once?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|