I have a WPF application where I have a column that should display one of the following:
If images are returned, display the images.
If a HTML text is returned, render the HTML table within the cell.
Can someone please tell me how I can do that?
For HTML, you may refer this link - http://pdgp.wordpress.com/2008/05/31/show-html-formatting-in-gridview-cells/
For showing Image, you may refer here - http://msdn.microsoft.com/en-us/library/2ab8kd75.aspx
Hope this helps.
[Update for Winforms DataGridView]
In order to display HTML, the only choice would be to override the Paint method I suppose. Alternatively, you may think of hosting a WebBrowserControl.
How to: Host Controls in Windows Forms DataGridView Cells:-
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx
Related
I am trying to add images to a listbox with a "continuous scroll" so the user does not have to press any buttons etc to load the next set of images. The images are stored in Isolated Storage. I will be starting with 500 images. Loading 500 images to a listbox obviously does not work and just eats up all resources in a few seconds. Based on my research I need to use data virtualization so the images are retreived when they are required (on-screen) and disposed of when not-required (of-screen), as opposed to loading them all at once. I have searched the web for examples but have only been able to find code which retreives and displays text etc to populate the listbox as oposed to images stored in IS. I "belive" I need to use an Image within a Data Template, within a listbox and then bind to an IList using a custom class. I can bind the list box to a basic IList and that works ok (only 50 images) but when it comes to creating a custom class etc its over my head. Does anyone have an example of what I need that they would be happy to share? I havent been programming a year yet and have found most of my App requirements to be achievable with a litte research but I cant find any good pages or video that explains this exact requirement and its driving me crazy as I have spent days on it.
Failing that I will have to pay Telerik for their support and use their DataBoundListBox or pay a third party to write it for me, but I thought I would try here before parting with hundreds of dollars!
Thanks for your time(s) in advance!
Here is a proper implementation of data virtualization: http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx
This is how you bind images to the image control: Image UriSource and Data Binding
To get data Data Virtualization on the Windows Phone 7 you can use the VirtualizingStackPanel class. In the MSDN you can find all the properties you may want to set. To use the control you put your list inside this control:
<VirtualizingStackPanel>
<YOUR LIST>
</VirtualizingStackPanel>
Since you would like to have a tutorial I can point you to Jevgeni TÅ¡aikin blog post on ItemsControl virtualization. If you want more check out the post from Shawn Oster on Improving ListBox Performance.
I need to render some Rich Text in the screen that needs to change following a timeline. In my iOS version I use the Web control and in Android version I use TextSpan.
I read some recommendations where people state that the WebControl is the best way to render rich text in Windows Phone 7 so I have a WebBrowser control that I populate with an HTML string. Everything works fine until I decide to programmatically change the content with a call to NavigateToString. The content gets changed but with a brief blink to a white screen in between.
As my program needs to update the contents of the WebBrowser control several times per second the screen turns all white from all the refreshes.
I am considering the painful idea of using TextBlocks with inline and LineBreaks but I will have to convert my HTML manually so I wanted to try to see if someone knows how to do this.
To replicate the issue just place a WebBrowser control on a page and update the content with NavigateToString to see the white transition blinking
I do a combination of OnNavigated and javascript. I start with Opacity = 0 and load a placeholder page into the control.
<html>
<head>
<script type="text/javascript">function setContent(s) { document.body.innerHTML = s; } </script>
</head>
<body></body>
</html>
In OnNavigated I set Opacity = 1 then I use InvokeScript to load my actual content.
webBrowser.InvokeScript("setContent", myContents);
In my case I am filling the entire page contents, though you might be able to write a more targetted piece of javascript if you are only changing certain pieces of the page.
The behavior is normal because the WebBrowser control basically has to re-render the entire page, even if you changed small parts of the content. Your best choice would be using RichTextBox - this will involve some manual text format processing.
I was going to suggest this:
WB_OnNavigating --> visibility = collapsed
WB_OnNavigated --> visibility = visible
Or a play on opacity. But these may be too slow given the multiple refreshes per second. Still may be worth a try to see what you get.
Is there any way the XAML background could be white or the HTML content's backcolor could match the page background?
Still looking for a better answer..
I have a requirement to save emails written in a RichTextBox to a database. Obviously, I would like to persist the formatting to the DB and send out HTML emails. However, this requires converting XAML to HTML which will be stored and then converting back if they are reloaded from the DB.
I have tried out the XAMLtoHTML converter. The problem I am getting is that the converter only works partially. It sets up all the formatting correctly in HTML but the text part is missing. I have followed this post:: XAML to HTML Conversion - WPF RichTextBox and had the same error but adding the tags didnt solve the problem.
Has anyone got experience with XAML to HTML conversions? Thanks
Consider using this free HTML Editor for silverlight instead. Html RichTextArea Control (Silverlight 4 Only).
You then load and save HTML and not bother with Xaml at all. Just be careful with the fontsizes, last time I looked only px sizes worked, pt sizes were not supported. You may want to fiddle with the samples font drop down so that the actual value is 1.33 the displayed size.
I'm working on a project that involves creating a custom graphical editor. The graphical editor has multiple tabs, and I want to create a preview function that will show a popup with Bitmap previews of the content of each of the tabs. However, the problem I'm running into is that the content for each of the tabs must be arranged before a proper preview can be generated for it. This means going into each of the tabs to ensure that they're rendered and arranged. Then, and only then, do the previews get properly generated, otherwise the previews have a size of 0x0. Does anybody know how to force an arrange of a content control so that I can get a properly sized preview generated ?
Apparently you can just call the 'Arrange' method directly, but you have to be careful about the rectangle you pass in as a parameter, because it can adversely affect the display of your control if you just want to force the object to draw itself (ie can force it to draw out of the desired position).
Here is a link to MSDN where it discusses the "arrangeOverride" method of a control.
I'm not sure this is what you need, but this method seems to be what you're asking about.
Hope this helps!
I have to do an animation in a WPF project .
That is,one of the windows should display person's photos like an album,
where i should be able to flip the pages to see each person's info.
Each page should contain a header Description of person and a Photo below.
I dont have expression blend.
What is the simple way to do this.I am new to animation featues of WPF.So wher should i begin and which control should i use?
Please provide some inputs.Code samples,links etc.
Thansk
SNA
Maybe this